cordova-broadcaster icon indicating copy to clipboard operation
cordova-broadcaster copied to clipboard

How to incorporate into existing plugins

Open nomaam opened this issue 4 years ago • 1 comments

I am trying to send a message from the inAppBrowser plugin (hardware back button) back to Javascript (Android)

So in Cordova onload i have

var listener = function( e ) {
//log: didShow received! userInfo: {"data":"test"}
console.log( "didShow received! userInfo: " + JSON.stringify(e)  );
}
window.broadcaster.addEventListener( "didShow", listener);

I am trying to modify InAppBrowserDialog.java and inside the hardware back button function

public void onBackPressed() {

I placed the example code for this broadcaster plugin

        final Intent intent = new Intent("didShow");

        final Bundle child = new Bundle();
        child.putString( "name", "joker");

        final Bundle b = new Bundle();
        b.putString( "data", "test");
        b.putBoolean( "valid", true );
        b.putBundle( "child", child );

        intent.putExtras( b);

        LocalBroadcastManager.getInstance(this).sendBroadcastSync(intent);

I am obviously not injecting this code correctly as there are numerous problems, none of the variables are recognized.

Are there imports / libraries I must also call to use this plugin inside other plugins? Is there an example provided that shows how to send messages back to Cordova from within other Java plugins?

Thank you

nomaam avatar Jan 19 '21 21:01 nomaam

hi @nomaam

I never tested this scenario so, currently, it is not possible to help you with that.

the only difference that I see is the context provided to get an instance of LocalBroadcastManager. You have used this (I guess plugin context) while my plugin use webView.getContext()

bsorrentino avatar Jan 20 '21 09:01 bsorrentino