0

I have built a Web app completely on Flutter and a few pages of this Webapp will be rendered in the Existing Native iOS and Android App through respective Webviews. In this architecture, the Use case is, There's a button inside the Webapp when clicked on From a Web Browser, should load the Web app's homepage, which works perfectly fine which I'm, achieving through await urlLauncher.launchUrl("$APP_DOMAIN/home).

But in The Native apps, When I click on that Button, It should redirect to Native App's homepage, i.e., when I click on that Button, Some message should be passed from the Webapp to my Webview, using which I'll just call finish() method in My android code which will take the User to the mobile app's Homepage.

In Web app, I'm able to distinguish whether the App is run on a Browser or on a Webview. Using that condition, I'm calling window.postMessage("$APP_DOMAIN/home", APP_DOMAIN); in Web app using 'dart:html' package.

In my Android app, Inside the Webview I tried these -

val myListener: WebViewCompat.WebMessageListener =
                WebViewCompat.WebMessageListener { view, message, sourceOrigin, isMainFrame, replyProxy -> 
                    Timber.d("onWebMessage: ${message.data}") 
}
if(WebViewFeature.isFeatureSupported(WebViewFeature.WEB_MESSAGE_LISTENER)) {
   WebViewCompat.addWebMessageListener(webView, "window", setOf(), myListener)
} else {
   Timber.d("Web_MESSAGE_LISTENER not supported")
}

0 Answers0