如何从CustomTabsClient获取Url更改

Mik*_*eps 7 android chrome-custom-tabs

如何在页面更改时获取URL,使用CustomTabsClient

例如,WebView有一个方法:

@Override
public void onPageStarted(WebView view, String url, Bitmap favicon){}
Run Code Online (Sandbox Code Playgroud)

我需要一个类似的方法CustomTabs.

我找到了这个:

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);
    }
});
Run Code Online (Sandbox Code Playgroud)

但我不确定这是否是我需要的.

Mat*_*ini 12

如何在页面更改时获取URL,使用CustomTabsClient

不幸的是你不能.Chromium bug跟踪器上还有一个未解决的问题:

https://code.google.com/p/chromium/issues/detail?id=543542

您现在唯一能做的就是知道选项卡何时开始或已完成加载页面,但您无法检索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;
        }
    }
});
Run Code Online (Sandbox Code Playgroud)

  • @kenyee你是否通过传递#newSession()返回的会话来创建你的chrome意图?新的CustomTabsIntent.Builder(会话); (4认同)
  • 有人得到 onNavigationEvent 来真正被调用吗?我尝试多次设置它,但它似乎从未被调用,并且我验证了它是在 .newSession() 调用中设置的:-P (2认同)