Search in sources :

Example 1 with BrowserNotInstalledException

use of com.amazonaws.mobileconnectors.cognitoauth.exceptions.BrowserNotInstalledException in project aws-sdk-android by aws-amplify.

the class AuthClient method launchCustomTabs.

/**
 * Launches the HostedUI webpage on a Custom Tab.
 * @param uri Required: {@link Uri}.
 * @param activity Activity to launch custom tabs from and which will listen for the intent completion.
 * @param browserPackage Optional string specifying the browser package to launch the specified url.
 *                       Launches intent chooser if set to null.
 */
private void launchCustomTabs(final Uri uri, final Activity activity, final String browserPackage) {
    try {
        if (!isBrowserInstalled()) {
            userHandler.onFailure(new BrowserNotInstalledException("No browsers installed."));
            return;
        }
        CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(mCustomTabsSession);
        mCustomTabsIntent = builder.build();
        if (pool.getCustomTabExtras() != null) {
            mCustomTabsIntent.intent.putExtras(pool.getCustomTabExtras());
        }
        if (browserPackage != null) {
            mCustomTabsIntent.intent.setPackage(browserPackage);
        } else if (customTabsPackageName != null) {
            mCustomTabsIntent.intent.setPackage(customTabsPackageName);
        }
        mCustomTabsIntent.intent.setData(uri);
        if (activity != null) {
            activity.startActivityForResult(CustomTabsManagerActivity.createStartIntent(context, mCustomTabsIntent.intent), CUSTOM_TABS_ACTIVITY_CODE);
        } else {
            Intent startIntent = CustomTabsManagerActivity.createStartIntent(context, mCustomTabsIntent.intent);
            startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_HISTORY);
            context.startActivity(startIntent);
        }
    } catch (final Exception e) {
        userHandler.onFailure(e);
    }
}
Also used : BrowserNotInstalledException(com.amazonaws.mobileconnectors.cognitoauth.exceptions.BrowserNotInstalledException) CustomTabsIntent(androidx.browser.customtabs.CustomTabsIntent) Intent(android.content.Intent) CustomTabsIntent(androidx.browser.customtabs.CustomTabsIntent) AuthServiceException(com.amazonaws.mobileconnectors.cognitoauth.exceptions.AuthServiceException) AuthClientException(com.amazonaws.mobileconnectors.cognitoauth.exceptions.AuthClientException) BrowserNotInstalledException(com.amazonaws.mobileconnectors.cognitoauth.exceptions.BrowserNotInstalledException) InvalidParameterException(java.security.InvalidParameterException) AuthInvalidGrantException(com.amazonaws.mobileconnectors.cognitoauth.exceptions.AuthInvalidGrantException) AuthNavigationException(com.amazonaws.mobileconnectors.cognitoauth.exceptions.AuthNavigationException)

Aggregations

Intent (android.content.Intent)1 CustomTabsIntent (androidx.browser.customtabs.CustomTabsIntent)1 AuthClientException (com.amazonaws.mobileconnectors.cognitoauth.exceptions.AuthClientException)1 AuthInvalidGrantException (com.amazonaws.mobileconnectors.cognitoauth.exceptions.AuthInvalidGrantException)1 AuthNavigationException (com.amazonaws.mobileconnectors.cognitoauth.exceptions.AuthNavigationException)1 AuthServiceException (com.amazonaws.mobileconnectors.cognitoauth.exceptions.AuthServiceException)1 BrowserNotInstalledException (com.amazonaws.mobileconnectors.cognitoauth.exceptions.BrowserNotInstalledException)1 InvalidParameterException (java.security.InvalidParameterException)1