11

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 Answer 1

18

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;
        }
    }
});
4
  • 2
    Has anyone gotten onNavigationEvent to actually get called? I tried setting this up multiple times but it never seems to get called and I verified it gets set in the .newSession() call :-P
    – kenyee
    Sep 13, 2016 at 20:07
  • 9
    @kenyee Did you create your chrome intent by passing in the session returned from #newSession()? new CustomTabsIntent.Builder(session);
    – sfreeman
    Sep 18, 2016 at 21:29
  • That was it @sfreeman...thanks much :-) They should just require builder take the session for a param.
    – kenyee
    Sep 19, 2016 at 18:02
  • @Mattia i have pass the session in Builder also but this onNavigationEvent(...) never seems to get called even a single time Aug 26, 2017 at 19:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.