How do you launch an activity from an implicit intent when the browser is in the background?

Viewed 178

I have an app that launches authentication in a Chrome custom tab and delivers the result back to my app via an implicit intent using an intent filter on an activity. This works fine as long as the custom tab remains in the foreground while the login flow completes on the web. However, if the user has two-factor authentication enabled, it's possible that their 2FA app will be in the foreground instead while the login flow completes. In this case, the implicit intent is never launched, and my activity is never launched.

This happens when using both Chrome custom tabs and the main Firefox app to open the login flow. I tried it on Android 9 and 10 to make sure it wasn't due to Android's restrictions on starting activities in the background in Android 10. It does not work on either OS.

Here is what the activity in my manifest looks like:

<activity
    android:name=".LoginCompleteActivity"
    android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />

        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />

        <data android:scheme="mycustomscheme" />
    </intent-filter>
</activity>

I have also tried including the host and pathPattern with the intent-filter, but that doesn't work either. How do you enforce opening an activity from the browser when the browser is in the background?

0 Answers
Related