Android 如何从CustomTabsClient获取Url更改
如何使用Android 如何从CustomTabsClient获取Url更改,android,chrome-custom-tabs,Android,Chrome Custom Tabs,如何使用CustomTabsClient在页面更改时获取url 例如,WebView有一个方法: @Override public void onPageStarted(WebView view, String url, Bitmap favicon){} 对于自定义选项卡,我需要类似的方法 我发现了这个: mClient.newSession(new CustomTabsCallback(){ @Override public void onNavigationEvent(i
CustomTabsClient
在页面更改时获取url
例如,WebView有一个方法:
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon){}
对于自定义选项卡
,我需要类似的方法
我发现了这个:
mClient.newSession(new CustomTabsCallback(){
@Override
public void onNavigationEvent(int navigationEvent, Bundle extras) {
super.onNavigationEvent(navigationEvent, extras);
}
@Override
public void extraCallback(String callbackName, Bundle args) {
super.extraCallback(callbackName, args);
}
});
但我不确定这是否是我需要的
如何使用CustomTabsClient
在页面更改时获取url
不幸的是你不能。Chromium bug tracker上还有一个未解决的问题:
您现在唯一能做的就是知道选项卡何时开始或完成加载页面,但您无法检索URL:
mClient.newSession(new CustomTabsCallback(){
@Override
public void onNavigationEvent(int navigationEvent, Bundle extras) {
Log.w(TAG, "onNavigationEvent: Code = " + navigationEvent);
switch (navigationEvent) {
case NAVIGATION_STARTED:
// Sent when the tab has started loading a page.
break;
case NAVIGATION_FINISHED:
// Sent when the tab has finished loading a page.
break;
case NAVIGATION_FAILED:
// Sent when the tab couldn't finish loading due to a failure.
break;
case NAVIGATION_ABORTED:
// Sent when loading was aborted by a user action before it finishes like clicking on a link
// or refreshing the page.
break;
}
}
});
有人在NavigationEvent上打过电话吗?我尝试过多次设置,但它似乎从未被调用,我在.newSession()调用中验证了它的设置:-P@kenyee您是否通过传入从#newSession()返回的会话来创建chrome意图?新建CustomTabsInt.Builder(会话);这就是@sfreeman…非常感谢:-)他们应该只要求builder为参数执行会话。@Mattia我也在builder中通过了会话,但这个onNavigationEvent(…)似乎从未被调用过,哪怕是一次