chrome-custom-tabs - 强制关闭 Chrome 自定义选项卡
问题描述
我想通过单击设备后退按钮关闭 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 操作。实际上,在许多用例中以这种方式工作会更好。
推荐阅读
- c# - 如何验证用户到他们自己的谷歌驱动器帐户?
- java - 线程“AWT-EventQueue-0”中的异常 java.lang.ArrayIndexOutOfBoundsException:12
- continuous-integration - 有没有办法覆盖 dbt Cloud CI 运行的模式名称?
- python - ParserError:预计第 32 行中有 2 个字段,看到 4
- javascript - 通过网络请求将订阅者添加到 Mailchimp 组/更新表单答案
- cypress - 在无头 Chrome 中运行 Cypress 测试
- javascript - 迭代问题“未捕获的错误:需要坐标”
- python - 提取字符串中的2个数字,用一个单词分隔
- php - 如何在 RESTful 服务中添加带有 POST 请求的订单?
- python - 如何解析Linux输入/输出ASCII与控制图最终字符串,使用golang或python或shell