7

I am using chrome custom tabs for getting oAuth connection request on the redirection from custom tabs I am redirected successfully in the app. The only problem remains is that the chrome custom tabs do not close on redirection stay in the stack.

Code for launching url in custom tabs is as follows.

customTabsIntent = new CustomTabsIntent.Builder(mCustomTabsSession)
                                                                .setToolbarColor(ContextCompat.getColor(getBaseContext(), R.color.colorPrimary))
                                                                .setStartAnimations(getBaseContext(),
                                                                        R.anim.slide_in_right, R.anim.slide_out_left)
                                                                .setExitAnimations(getBaseContext(),
                                                                        android.R.anim.slide_in_left, android.R.anim.slide_out_right)
                                                                .setShowTitle(true)
                                                                .build();
                                                        customTabsIntent.intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
                                                       customTabsIntent.intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
 customTabsIntent.launchUrl(Settings_Activity.this, Uri.parse(fitbitUrlBuilder.toString()));

I tried using "singleTask" and "singleInstance" in manifest file but still the issue persist.

If I only use intent "FLAG_NO_HISTORY" it works. But I need to forcefully need to use "FLAG_ACTIVITY_NEW_TASK" since there is a certain edge case for e.g if the token of the specific site is deleted and we try reauthenticate the browser just collapses on android version 7.1 and need to manually start the app again.

Any help on this appreciated.

Sutirth
  • 1,217
  • 4
  • 15
  • 26
  • collapsing is a sign of something going wrong. What does it print to the system log (the one viewable with 'adb logcat')? Does it happen on other Android versions? If there is a crash, please file a bug using the bug template as mentioned in https://github.com/GoogleChrome/custom-tabs-client – Egor Pasko Apr 10 '17 at 12:57
  • @EgorPasko for the certain edge case there is no crash and system log doesn't print anything. It might be just a bug from chrome custom tabs i guess – Sutirth Apr 11 '17 at 06:21
  • can you please file a bug against custom tabs (using a link reachable by a link I provided:)? – Egor Pasko Apr 11 '17 at 09:18
  • @EgorPasko Sure would do it :) – Sutirth Apr 11 '17 at 09:24
  • @Sutirth , hi . i am also using fitbit and having a problem in getting redirection from fit bit to app can you please take a look at my question https://stackoverflow.com/questions/52629467/fit-bit-login-using-chrome-custom-tabs-no-call-back-in-my-application – hamza khan Oct 08 '18 at 08:29

1 Answers1

8

I had the same issue when trying to authenticate an oAuth provider. I got the code working using the custom tabs 25.3.1, and using addFlags instead of setFlags:

build.gradle

dependencies {
  ...
  compile 'com.android.support:customtabs:25.3.1'
}

MyActivity.java

public void dispatchAuthIntent() {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
    // Use Chrome Custom Tabs
    CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder()
        .setToolbarColor(ContextCompat.getColor(getBaseContext(), R.color.brand_blue_dark))
        .setShowTitle(true)
        .build();

    customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
    customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    customTabsIntent.launchUrl(this, Uri.parse(url));
  }
  // ...
}
Chris Blunt
  • 986
  • 9
  • 23