Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Receiving broadcast intents with cordova-broadcaster

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

like image 565
Yann Olaf Avatar asked Jan 30 '26 14:01

Yann Olaf


1 Answers

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);
    }
}
like image 128
bsorrentino Avatar answered Feb 02 '26 03:02

bsorrentino