Search code examples
androidoauthdropboxdropbox-api

How to identificate if it's a Dropbox auth?


I'm planning to use different storage types in my app. I'm starting from Dropbox. It have useful method, which goes to intent, authorize user, and returns to the last activity:

String key = settings.getString ("dropbox_key", "");
Auth.startOAuth2Authentication (SettingsActivity.this, key);

I can work with its data using the onResume () method in activity, but how can I identificate that I returned to it by Dropbox auth, not Google and others Oauth apps, because I want to work with it in one activity, but get different data and write it to the different settings values. I think it will be a kind of BROWSABLE category type activity, which is opens by URL, which Dropbox using as callback and pass necessary params to it, but I tried to get its data by getIntent().getData(), but it always gets null.

Dropbox activity connects with their default code, so I can't pass my own activity uri:

     <activity
        android:name="com.dropbox.core.android.AuthActivity"
        android:configChanges="orientation|keyboard"
        android:launchMode="singleTask"
        android:theme="@android:style/Theme.Translucent.NoTitleBar"
    >
        <intent-filter>

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

            <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 in advance.


Solution

  • If you're using the Dropbox API v2 Java SDK in an Android app, you should be handling the end of the app authorization flow in your onResume as shown in the example app.

    You can and use the return value of Auth.getOAuth2Token to check if the user is coming back from the Dropbox app authorization flow. That is, if the return value is non-null, it's an access token returned as the result of the Dropbox app authorization flow.

    If it is null, that indicates that the user is not coming back to the app as a result of the Dropbox app authorization flow.