3

I'm trying to work with the Chrome CustomTabs on Android, but I have a problem about use of CustomTabsCallback. So, I searched on the web some examples or documentation to implement in my code, but I unfortunatelly I did not find anything...
I need to receive a postMessage sent by the hosted web page and read the content inside it. The postMessage was sent using "*" as origin, but I don't think that's the real problem.

Here my code:

CustomTabsClient.bindCustomTabsService(context, CUSTOM_TAB_PACKAGE_NAME, new CustomTabsServiceConnection() {
        @Override
        public void onCustomTabsServiceConnected(ComponentName name, CustomTabsClient client) {
            mClient = client;
            mClient.warmup(0);
            CustomTabsSession session = mClient.newSession(new CustomTabsCallback() {
                @Override
                public void onPostMessage(String message, Bundle extras) {
                    // Here the method not called by CustomTabs
                    super.onPostMessage(message, extras);
                }

                @Override
                public void onMessageChannelReady(Bundle extras) {
                    super.onMessageChannelReady(extras);
                }

                @Override
                public void onNavigationEvent(int navigationEvent, Bundle extras) {
                    super.onNavigationEvent(navigationEvent, extras);
                }
            });
            session.mayLaunchUrl(uri, null, null);
            CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(session);
            CustomTabsIntent customTabsIntent = builder.build();
            customTabsIntent.launchUrl(context, uri);
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {
            mClient = null;
        }
    });

I accept all suggestions, it's making me crazy.

Thanks in advance.

rik194
  • 118
  • 1
  • 12

0 Answers0