cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Android app fails authentication if Dropbox app isn't installed...

Android app fails authentication if Dropbox app isn't installed...

T3chDad
Helpful | Level 6
Go to solution

Dropbox API/SDK 3.0.5

Android target 19

 

After verifying there is no saved access token, I'm kicking off the authentication flow with:

Auth.startOAuth2Authentication(getApplicationContext(), getString(R.string.app_key));

And then I retrieve/check the access token in the onResume() of my activity.  If the Dropbox app is installed on the device, everything works great.  If the Dropbox app isn't installed, no token is retrievable/available when control is passed back to the activity.  I am prompted for credentials and permissions via the Dropbox website.  I have the appropriate Dropbox activity defined in my AndroidManifest.xml with the appropriate db key.

<data android:scheme="db-xxxxxxxxxxxxxxx" />

 I've been searching all day and haven't hit on the right search string to obtain any insight.  Any help would be greatly appreciated.  Thanks.

1 Accepted Solution

Accepted Solutions

T3chDad
Helpful | Level 6
Go to solution

Alright...I figured it out.  Silly me.  I had two Dropbox activity declarations in my manifest.  I had the "old" original entry with my production app key (from v1 days) and I had the new v2 api entry with a different app key that I use for testing.  Once I removed the old activity entry and changed the key on the new activity entry, everything worked properly.  My Dropbox activities in my manifest as they were before the fix are below for reference.

<!-- Old v1 Activity -->
<activity android:name="com.dropbox.client2.android.AuthActivity" android:launchMode="singleTask" android:configChanges="orientation|keyboard"> <intent-filter> <!-- Change this to be db- followed by your app key --> <data android:scheme="db-xxxxxxxxxx(CorrectKey)" /> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.BROWSABLE"/> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity>
<!--New v2 Activity --> <activity android:name="com.dropbox.core.android.AuthActivity" android:configChanges="orientation|keyboard" android:launchMode="singleTask"> <intent-filter> <!-- Change this to be db- followed by your app key --> <data android:scheme="db-yyyyyyyyyyyyy(WrongKey)" /> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.BROWSABLE" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity>

Thanks for your help and patience in getting me pointed in the right direction.

 

 

 

View solution in original post

6 Replies 6

Greg-DB
Dropbox Staff
Go to solution
Can you elaborate on what you mean when you say "no token is retrievable/available when control is passed back to the activity"? What piece of code isn't behaving as expected, and what does it do instead?

For reference, to receive the token you should be calling Auth.getOAuth2Token as shown here:

https://github.com/dropbox/dropbox-sdk-java/blob/master/examples/android/src/main/java/com/dropbox/c...

T3chDad
Helpful | Level 6
Go to solution

Using that call returns null after authenticating to Dropbox and allowing the access via the authentication web page. Here's my code that's in my onReturn().

 

ACCESS_TOKEN = Auth.getOAuth2Token();
if (ACCESS_TOKEN != null) {
System.out.println("-------Got token from Auth session");
prefs.edit().putString("access-token", ACCESS_TOKEN).apply();
Toast.makeText(getApplicationContext(), "Dropbox authentication succeeded...", Toast.LENGTH_SHORT).show();
new DropboxGetFileInfo().execute();
} else {
System.out.println("-------Authentication either failed or was canceled.");
Toast.makeText(getApplicationContext(), "Dropbox authentication failed...", Toast.LENGTH_SHORT).show();
Intent i = new Intent(Synchronize.this, FlightLog.class);
setResult(RESULT_CANCELED, i);
finish();
}

Remember, all this works fine IF the Dropbox app is installed on the device.  The access token is null when the Dropbox app isn't installed and it's using the authentication pages on the Dropbox website.

Greg-DB
Dropbox Staff
Go to solution

Thanks! You shouldn't have to do anything different depending on whether or not the official Dropbox app is installed. They should both use the same flow.

 

For reference, does the Android sample app display the same issue for you?

 

Also, I noticed you mentioned that code is in "onReturn". Did you mean "onResume"?

T3chDad
Helpful | Level 6
Go to solution

Yes, I meant onResume().  It works with the example app, so I must have broken something by consolidating everything to one activity and class.  I'll look into finding the crucial difference and report back when I have it working.

 

 

 

T3chDad
Helpful | Level 6
Go to solution

Alright...I figured it out.  Silly me.  I had two Dropbox activity declarations in my manifest.  I had the "old" original entry with my production app key (from v1 days) and I had the new v2 api entry with a different app key that I use for testing.  Once I removed the old activity entry and changed the key on the new activity entry, everything worked properly.  My Dropbox activities in my manifest as they were before the fix are below for reference.

<!-- Old v1 Activity -->
<activity android:name="com.dropbox.client2.android.AuthActivity" android:launchMode="singleTask" android:configChanges="orientation|keyboard"> <intent-filter> <!-- Change this to be db- followed by your app key --> <data android:scheme="db-xxxxxxxxxx(CorrectKey)" /> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.BROWSABLE"/> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity>
<!--New v2 Activity --> <activity android:name="com.dropbox.core.android.AuthActivity" android:configChanges="orientation|keyboard" android:launchMode="singleTask"> <intent-filter> <!-- Change this to be db- followed by your app key --> <data android:scheme="db-yyyyyyyyyyyyy(WrongKey)" /> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.BROWSABLE" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity>

Thanks for your help and patience in getting me pointed in the right direction.

 

 

 

Greg-DB
Dropbox Staff
Go to solution
Thanks for following up. I'm glad to hear you sorted this out.
Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    T3chDad Helpful | Level 6
What do Dropbox user levels mean?