bsorrentino / cordova-broadcaster

Cordova Plugin to allow message exchange between javascript and native (and viceversa)
MIT License
113 stars 53 forks source link

broadcaster extras are missing #30

Closed schinnaraju closed 6 years ago

schinnaraju commented 6 years ago
let listener = function( e ) {
  console.log('barcode :: ' + JSON.stringify(e));
}
window.broadcaster.addEventListener( "BarcodeReader", listener);

Android code Intent intentVal = new Intent("BarcodeReader");


Bundle b = new Bundle();

b.putString( "barcode", content+"");

b.putString( "userdata", "{ \"data\": \"test\"}" );

intent.putExtras( b);


LocalBroadcastManager.getInstance(MainActivity.this).sendBroadcastSync(intentVal);

but e prints as {} instead of actual data.

bsorrentino commented 6 years ago

Hi, thanks for feedback

In android the plugin retrieves extended data from the intent named userdata as shown below

final Bundle b = intent.getExtras();

final String userData = b.getString("userdata", "{}");
schinnaraju commented 6 years ago

The broadcast work but the extra data are empty when i parse from Javascript code. Is there anything missing in the code (I have updated with native code as well)

bsorrentino commented 6 years ago

what does you mean with extra ?. As wrote above the plugin (by default) get only field userdata from extras

schinnaraju commented 6 years ago

i mean am not getting "userdata"

bsorrentino commented 6 years ago

Ok got it

Let me check

bsorrentino commented 6 years ago

One of reason could be that the string passed to extra is not valid json object

bsorrentino commented 6 years ago

check out the new version 3.0.0 it doesn't use userdata anymore