I am trying to use the cordova-broadcaster plugin to receive android broadcast intents. I register for the broadcast event
window.broadcaster.addEventListener("com.android.action.SEND_SCAN_RESULT", function (e) {
console.log("com.android.action.SEND_SCAN_RESULT received.");
});
console.log("com.android.action.SEND_SCAN_RESULT registered");
but if the intent gets fired
V/ActivityManager( 775): Broadcast: Intent { act=com.android.action.SEND_SCAN_RESULT flg=0x10 (has extras) } ordered=false userid=0 callerApp=ProcessRecord{1418277c 775:system/1000}
the callback does not get triggered.
The only log message is
com.android.action.SEND_SCAN_RESULT registered
Currently the plugin doesn't manage external broadcast events but only the local ones
Probably solution could be handle the external event in android and then fire it up to javascript
take a look here
Try this (it should works)
manifest
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<receiver android:name="MyReceiver" >
<intent-filter>
<action android:name="com.android.action.SEND_SCAN_RESULT" >
</action>
</intent-filter>
</receiver>
</application>
Receiver
public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
LocalBroadcastManager.getInstance(context).sendBroadcastSync(intent);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With