NativeScript Scanner Event

Hi Experts,
I am building nativescript plugin for scanner event using datawedge API.
I am not able to receive broadcast event. How can i create listner in nativescript plugin to receive scanned data.

Below is my code.
registerBroadCastReceiver(){

const cb = (<any>android.content.BroadcastReceiver).extend({
onReceive: (context, data) => {
console.log("test-message receieved");
}
}
);

var _onReceivedCallback = new cb();
const intentFilter = "com.dwmdk.ACTION"
var filter = new android.content.IntentFilter();
filter.addCategory(android.content.Intent.CATEGORY_DEFAULT);
filter.addAction(intentFilter);
var broadcastManager = androidx.localbroadcastmanager.content.LocalBroadcastManager.getInstance(utils.ad.getApplicationContext());
broadcastManager.registerReceiver(_onReceivedCallback, new android.content.IntentFilter(intentFilter));

console.log("Registration Completed");
}

Regards
Manish

Darryn Campbell
Hi, you are using the

Hi, you are using the localbroadcastmanager class, that is only used to send and receive local broadcasts within your process.  You need to use a Broadcast Receiver, https://developer.android.com/guide/components/broadcasts

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Manish Meshram
Hi Darryn,

Hi Darryn,
I tried using Broadcast Receiver but it did not work, i was checking below issue , it mentioned to use the instance of LocalBroadcastManager and register a callback manually
https://github.com/NativeScript/android-runtime/issues/1351

I also tried below code..
private onScanBroadCastReceive() {

let _onScanReceivedCallback = undefined;
//const intentFilter = "com.symbol.datawedge.api.NOTIFICATION_ACTION";
const intentFilter = "com.dwmdk.ACTION"
var filter = new android.content.IntentFilter();
filter.addCategory(android.content.Intent.CATEGORY_DEFAULT);
filter.addAction(intentFilter);
// app.android.context.registerReceiver(_onScanReceivedCallback, filter);
console.log("Register Receiver");

app.android.registerBroadcastReceiver(intentFilter,
function onReceiveCallback(_context: android.content.Context, intent: android.content.Intent) {

console.log("Intent Action" + intent.getAction());
if (intent.hasExtra("com.symbol.datawedge.api.NOTIFICATION")) {
console.log("Datawedge Notification");
}
const result = intent.getStringExtra("RESULT");
const resultformat = intent.getStringExtra("RESULT_FORMAT");
console.log("Result" + result);

// var level = intent.getIntExtra(android.os.BatteryManager.EXTRA_LEVEL, -1);
// var scale = intent.getIntExtra(android.os.BatteryManager.EXTRA_SCALE, -1);

});
console.log("Broadcast Receiver End");
}

regards
Manish

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Topic locked