We’re Still Here to Help (Even Over the Holidays!) - find out more here.
Forum Discussion
T3chDad
9 years agoHelpful | Level 6
Android app fails authentication if Dropbox app isn't installed...
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.
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.
6 Replies
- Greg-DB9 years ago
Dropbox Community Moderator
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/core/examples/android/DropboxActivity.java#L22 - T3chDad9 years agoHelpful | Level 6
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-DB9 years ago
Dropbox Community Moderator
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"?
- T3chDad9 years agoHelpful | Level 6
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.
- T3chDad9 years agoHelpful | Level 6
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-DB9 years ago
Dropbox Community Moderator
Thanks for following up. I'm glad to hear you sorted this out.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!