Chrome CustomTabs CustomTabsCallback onPostMessage not called

拥有回忆 提交于 2019-12-11 06:29:16

问题


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.

来源:https://stackoverflow.com/questions/51499759/chrome-customtabs-customtabscallback-onpostmessage-not-called

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