Reputation: 1267
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.
Upvotes: 7
Views: 4379
Reputation: 996
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));
}
// ...
}
Upvotes: 9