我正在尝试确定用户何时在 Chrome 中打开 Chrome 自定义选项卡(菜单中的“在 Chrome 中打开”选项)。
我的导航回调返回事件代码 6,这与用户关闭自定义选项卡时返回的代码相同。有没有办法区分用户是关闭了自定义选项卡还是在 Chrome 中打开了它?
我正在尝试确定用户何时在 Chrome 中打开 Chrome 自定义选项卡(菜单中的“在 Chrome 中打开”选项)。
我的导航回调返回事件代码 6,这与用户关闭自定义选项卡时返回的代码相同。有没有办法区分用户是关闭了自定义选项卡还是在 Chrome 中打开了它?
导航代码 6 表示 CustomTabs 活动不再可见,因为用户已导航回启动 CustomTabs 意图的活动或另一个活动,在这种情况下 Chrome 已启动,已发生。
当用户从 CustomTabs 活动导航到 Chrome 时,您将获得导航代码 6,当点击后退按钮时,将发送另一个事件,代码 5(选项卡再次可见)。在这种情况下,您的 CustomActivity 仍然可见,之前的活动已完成,启动意图的活动仍处于暂停状态。
当您onActivityResult()
在启动会话的活动上调用导航代码 6 和方法时,为活动启动 CustomTabs 可能会解决您的问题。
public void openUrlForResult(String url, int requestCode){
CustomTabsIntent customTabsIntent = buildCustomTabIntent(mCustomTabSession);
customTabsIntent.intent.setData(Uri.parse(url));
mContext.startActivityForResult(customTabsIntent.intent, requestCode);
}