【问题标题】:Chrome Custom Tabs does not closes on redirectionChrome 自定义选项卡不会在重定向时关闭
【发布时间】:2017-09-05 05:10:48
【问题描述】:

我正在使用 chrome 自定义选项卡从自定义选项卡的重定向中获取 oAuth 连接请求,我在应用程序中成功重定向。剩下的唯一问题是 chrome 自定义选项卡在重定向时不会关闭留在堆栈中。

在自定义标签中启动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()));

我尝试在清单文件中使用“singleTask”和“singleInstance”,但问题仍然存在。

如果我只使用意图“FLAG_NO_HISTORY”,它就可以工作。 但是我需要强制需要使用“FLAG_ACTIVITY_NEW_TASK”,因为存在某种边缘情况,例如,如果特定站点的令牌被删除 我们尝试重新验证浏览器刚刚在 android 版本 7.1 上崩溃,需要再次手动启动应用程序。

对此的任何帮助表示赞赏。

【问题讨论】:

  • 崩溃是出现问题的迹象。它打印到系统日志(使用“adb logcat”可查看的日志)中的内容是什么?它是否发生在其他 Android 版本上?如果发生崩溃,请使用github.com/GoogleChrome/custom-tabs-client中提到的错误模板提交错误
  • @EgorPasko 对于某些极端情况没有崩溃并且系统日志不打印任何内容。我猜这可能只是 chrome 自定义标签的一个错误
  • 能否请您针对自定义选项卡提交错误(使用可通过我提供的链接访问的链接:)?
  • @EgorPasko 当然会这样做:)
  • @Sutirth,嗨。我也在使用 fitbit 并且在从 fit bit 重定向到应用程序时遇到问题你能看看我的问题stackoverflow.com/questions/52629467/…

标签: android oauth-2.0 fitbit chrome-custom-tabs


【解决方案1】:

我在尝试对 oAuth 提供者进行身份验证时遇到了同样的问题。我使用自定义选项卡 25.3.1 并使用 addFlags 而不是 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));
  }
  // ...
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-02
    • 2023-03-18
    相关资源
    最近更新 更多