Question

Surprisingly hard to find good insight into this, but I need to detect when the Cordova webview has finished loading so that I can run some initialization code on the native side. This code makes callbacks to the webview's javascript so the javascript must be in place and loaded (hence the need to be notified when webview has finished loading.

The only examples I've found are for detecting when a WebViewClient has finished loading, but I need to know when the initial phonegap webview has finished loading.

I'm newer to Android, coming in from the iOS world, and used to having a webviewDidFinishLoading method available to me. Hopefully there is a similar way to handle this in java for Android.

Was it helpful?

Solution

Here's a possible work-around you can explore:

Create an Apache Cordova Plugin for Android and call like this in your JavaScript code:

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {
   if (isAndroid) {
       cordova.exec(function(winParam) {}, function(error) {}, "service", "webviewDidFinishLoading", []);
   }
}     

cordova.exec details here. isAndroid details here.

You would add the native code you need to execute after the WebView has started inside the webviewDidFinishLoading method of the service plugin.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top