如何判断用户何时从菜单中选择"Open in Chrome"



我试图确定用户何时在Chrome中打开Chrome自定义选项卡(菜单中的"在Chrome中开启"选项)。

我的导航回调返回一个事件代码6,这与用户关闭自定义选项卡时返回的代码相同。有没有办法区分用户是关闭了自定义选项卡还是在Chrome中打开了自定义选项卡?

导航代码6意味着CustomTabs活动不再可见,因为用户已经导航回启动CustomTabs意图的活动,或者发生了另一个活动,在本例中,Chrome已经启动。

当用户从CustomTabs活动导航到Chrome时,您会得到导航代码6,当按下后退按钮时,会发送另一个事件,代码为5(选项卡再次可见)。在这种情况下,CustomActivity仍然可见,上一个活动已完成,启动意图的活动仍然暂停。

当您对启动会话的活动调用了导航代码6和onActivityResult()方法时,为活动启动CustomTabs可能会解决您的问题。

public void openUrlForResult(String url, int requestCode){
    CustomTabsIntent customTabsIntent = buildCustomTabIntent(mCustomTabSession);
    customTabsIntent.intent.setData(Uri.parse(url));
    mContext.startActivityForResult(customTabsIntent.intent, requestCode);
}

最新更新