Aws-sdk-android: AuthClient throws error when missing Chrome CustomTabs

Created on 5 Oct 2018  路  13Comments  路  Source: aws-amplify/aws-sdk-android

On a device that has chrome browser uninstalled or disabled, I get this error from the AuthClient

android.content.ActivityNotFoundException: No Activity found to handle Intent { 
act=android.intent.action.VIEW dat=... flg=0x50000000 pkg=com.android.chrome 
launchParam=MultiScreenLaunchParams { mDisplayId=0 mFlags=0 } (has extras) }

Any suggested work around for this?

Cognito Feature Request

Most helpful comment

Given the interest on this I'll add the feature request to our backlog to consider and as we get more +1s on this can investigate the level of effort to add support for other browsers.

All 13 comments

@jia-tse-zocdoc Sorry for the inconvenience caused. AWS SDK for Android - CognitoAuth relies on Chrome Custom Tabs for the Hosted UI. We have a strong dependency on the Chrome Custom Tabs library.

@kvasukib -- what is the suggested workflow for those users who don't have chrome tabs enabled?

Any news on this topic?
We really need it to work with any browser because the company which wants to use this has its own secure browser and also because it will also be used in China, where Google Chrome is not that used.

I'm also curious on a resolution of this topic. My team also needs it to work on devices that may have disabled Chrome.

Also curious..

Guys, please let us know what we can do about this issue. For our customers is really important to be able to use it without Google Chrome because it will be highly used in China and also the new Huawei devices don't support Google Chrome anymore

I'm seeing many users running in to this problem too.

It can be easily reproduced by disabling Chrome through Chrome's app info screen.

According to the documentation custom tabs supports most browsers
https://developers.google.com/web/android/custom-tabs/implementation-guide

I don't have any experience with the custom tabs library but it looks like this line is specifying that the intent should only be handled by the Chrome browser
https://github.com/aws-amplify/aws-sdk-android/blob/6c63c5a194d8be06d9a82c65d2d56166bac3e008/aws-android-sdk-cognitoauth/src/main/java/com/amazonaws/mobileconnectors/cognitoauth/AuthClient.java#L601

Would it be possible to allow other browsers to handle this intent? Or catch the ActivityNotFoundException and use a webview?

Given the interest on this I'll add the feature request to our backlog to consider and as we get more +1s on this can investigate the level of effort to add support for other browsers.

Just merged the implementation for this - it will go out in the next release.

I'll post some instructions for using it here when that's deployed.

@TrekSoft Is this fix in 2.19.1?

Yes it is! To use this feature, you can set the new option inside either SignInUIOptions or SignOutOptions to the browser package you want to use instead of Chrome.

SignInUIOptions signInUIOptions = SignInUIOptions.builder()
                .hostedUIOptions(<your hosted UI options object here>)
                .browserPackage("org.mozilla.firefox")
                .build();

SignOutOptions.builder().browserPackage("org.mozilla.firefox").invalidateTokens(true).build()

Note that the browser you choose must support custom tabs. Here is a code snippet that can identify which browsers are present on the device (if any) which support custom tabs.

    public static ArrayList<ResolveInfo> getCustomTabsPackages(Context context) {
        PackageManager pm = context.getPackageManager();
        // Get default VIEW intent handler.
        Intent activityIntent = new Intent()
                .setAction(Intent.ACTION_VIEW)
                .addCategory(Intent.CATEGORY_BROWSABLE)
                .setData(Uri.fromParts("http", "", null));

        // Get all apps that can handle VIEW intents.
        List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(activityIntent, 0);
        ArrayList<ResolveInfo> packagesSupportingCustomTabs = new ArrayList<>();
        for (ResolveInfo info : resolvedActivityList) {
            Intent serviceIntent = new Intent();
            serviceIntent.setAction(ACTION_CUSTOM_TABS_CONNECTION);
            serviceIntent.setPackage(info.activityInfo.packageName);
            // Check if this package also resolves the Custom Tabs service.
            if (pm.resolveService(serviceIntent, 0) != null) {
                packagesSupportingCustomTabs.add(info);
            }
        }
        return packagesSupportingCustomTabs;
    }

@TrekSoft signInWithWebUI is still affected by this, and appears to not accept SignOutOptions. Am I missing something?

Yeah that's Amplify Auth - different from AWSMobileClient. So your comment on this issue is the correct issue to be discussing that on: https://github.com/aws-amplify/amplify-android/issues/678

Was this page helpful?
0 / 5 - 0 ratings