1

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

1 回答 1

1

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

于 2019-02-19T08:01:39.713 回答