我想通过单击设备后退按钮来关闭 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/