Handling URL Scheme

To receive incoming deep-link to your RedirectURL from the trusted webview, you need to add some setup your project.

You can check this complete guide on deep-links in Android.

Here's an example on receiving an incoming link of cotterexample://login

AndroidManifest.xml
<activity android:name="com.example.cotterexample.Login">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <!-- Accepts URIs that begin with "cotterexample://login" -->
        <data android:scheme="cotterexample"
            android:host="login" />
    </intent-filter>
</activity>

Read data from incoming intents

You should generally do this during onCreate() or onStart()

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Read data from incoming intents 
    Intent intent = getIntent();
    if (Intent.ACTION_VIEW.equals(intent.getAction())) {
        Uri uri = intent.getData();
        // Use this data to perform your http request to get Cotter token 
        String authCode = uri.getQueryParameter(AUTH_CODE);
        String state = uri.getQueryParameter(STATE);
        String challengeID = uri.getQueryParameter(CHALLENGE_ID);
    }
}

Last updated