How to get Url change from CustomTabsClient

孤人 提交于 2019-11-30 04:37:41

问题


How to get the url when the page changes, using CustomTabsClient?

For example WebView has a method:

@Override
public void onPageStarted(WebView view, String url, Bitmap favicon){}

I need a similar method for CustomTabs.

I have found this one:

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);
    }
});

But I am not sure if this is the one I need.


回答1:


How to get the url when the page changes, using CustomTabsClient?

Unfortunately you can't. There is also an open issue on the Chromium bug tracker:

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

The only thing you can do now is to know when the tab has started or finished to loading the page, but you can't retrieve the 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;
        }
    }
});


来源:https://stackoverflow.com/questions/33343917/how-to-get-url-change-from-customtabsclient

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!