简体   繁体   English

Chrome自定义标签在重定向时不会关闭

[英]Chrome Custom Tabs does not closes on redirection

I am using chrome custom tabs for getting oAuth connection request on the redirection from custom tabs I am redirected successfully in the app. 我正在使用chrome自定义选项卡从自定义选项卡重定向获取oAuth连接请求我在应用程序中成功重定向。 The only problem remains is that the chrome custom tabs do not close on redirection stay in the stack. 唯一的问题仍然是chrome自定义选项卡在重定向时不会关闭保留在堆栈中。

Code for launching url in custom tabs is as follows. 在自定义选项卡中启动URL的代码如下。

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. 我尝试在清单文件中使用“singleTask”和“singleInstance”,但问题仍然存在。

If I only use intent "FLAG_NO_HISTORY" it works. 如果我只使用意图“FLAG_NO_HISTORY”它可以工作。 But I need to forcefully need to use "FLAG_ACTIVITY_NEW_TASK" since there is a certain edge case for eg 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. 但我需要强行使用“FLAG_ACTIVITY_NEW_TASK”,因为有一些边缘情况,例如,如果特定网站的令牌被删除,我们尝试重新认证浏览器只是在Android版本7.1上崩溃并需要再次手动启动应用程序。

Any help on this appreciated. 对此有任何帮助表示赞赏。

I had the same issue when trying to authenticate an oAuth provider. 尝试验证oAuth提供程序时,我遇到了同样的问题。 I got the code working using the custom tabs 25.3.1, and using addFlags instead of setFlags : 我使用自定义选项卡25.3.1,并使用addFlags而不是setFlags使代码正常工作:

build.gradle 的build.gradle

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

MyActivity.java 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));
  }
  // ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM