In my Cordova application, I am utilizing a native plugin on Android (with plans for other platforms in the future).
The plugin is loaded when the application starts (
<param name="onload" value="true" />
in plugin.xml) and the native code performs tasks within the initialize
method (overloaded from the CordovaPlugin
class).
After completing work in the initialize
method, an event is generated at a later time that needs to be delivered to the javascript API.
I'm wondering if there's a way to asynchronously communicate with the javascript from the native side of the plugin without first initiating communication from the javascript side. (If I were to initiate communication from JS->Java, I would receive a CallbackContext that could be used for callbacks.)
I came across this https://github.com/apache/cordova-android/blob/master/framework/src/org/apache/cordova/NativeToJsMessageQueue.java but I'm unsure how to use it as there seems to be no documentation available - I'm also uncertain if it's even meant for public usage.
Can I utilize
webview.loadUrl("javascript: ... ");
to make calls into the javascript side, or will this potentially disrupt or interfere with the cordova framework operating in JS?
I'd like to know if there's a recommended approach for achieving this task and whether it's supported across different platforms (or if the concepts can be applied to other platforms).
Thank you