chrome-custom-tabs - 强制关闭 Chrome 自定义标签

标签 chrome-custom-tabs android-customtabs

我想通过单击设备后退按钮来关闭 Chrome 自定义选项卡,但它仅在自定义选项卡暂时没有历史记录时才有效;当有剩余历史记录时,单击设备后退按钮只会将自定义选项卡后退到其历史记录中的页面。我可以强制自定义选项卡在任何时候忽略历史记录并立即关闭自定义选项卡吗?

我尝试了自定义选项卡的不同选项,如下所示,但似乎对我的目的没有帮助。我非常感谢你的想法。谢谢!

customTabsIntent.intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
customTabsIntent.intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
customTabsIntent.intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

我当前的代码是

String url = eacharticle.get("url");
String PACKAGE_NAME = "com.android.chrome";
android.support.customtabs.CustomTabsIntent customTabsIntent = new android.support.customtabs.CustomTabsIntent.Builder().setShowTitle(true).build();
customTabsIntent.intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
customTabsIntent.intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
customTabsIntent.intent.setData(Uri.parse(url));
java.util.List<android.content.pm.ResolveInfo> resolveInfoList = context.getPackageManager().queryIntentActivities(customTabsIntent.intent, android.content.pm.PackageManager.MATCH_DEFAULT_ONLY);
for (android.content.pm.ResolveInfo resolveInfo : resolveInfoList) {
String packageName = resolveInfo.activityInfo.packageName;
if(PACKAGE_NAME.equals(packageName))
customTabsIntent.intent.setPackage(PACKAGE_NAME); // force use chrome if installed
}
customTabsIntent.launchUrl(context, Uri.parse(url));

最佳答案

我认为目前没有选项可以执行此操作,因为我们无法覆盖 chrome 自定义选项卡上的 onBackPressed 操作。实际上,在许多用例中以这种方式工作会更好。

关于chrome-custom-tabs - 强制关闭 Chrome 自定义标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54611878/

相关文章:

deep-linking - 未处理的应用程序链接的自定义选项卡

android - 如何设置默认的 Chrome 自定义标签不必显示 “open with”

java - 通过 CustomTab 或 Chrome 发布数据

android - 从最近和历史中排除 Activity

Android 11、自定义标签和 FLAG_ACTIVITY_CLEAR_TOP

android - 如何使用 Chrome 自定义选项卡进行 OAuth 2.0 登录 (Fitbit API)

具有深层链接的 Android 自定义 chrome 选项卡

android - WebView 与 Chrome 自定义选项卡

android - Chrome 自定义标签 : Why is CustomTabsClient. bindCustomTabsService() 无法正常工作?

android - 如何隐藏自定义选项卡的 URL?