One day a client needed an app for a rugged PDA for their warehouse.
As a growing developer who got into the software development world through NativeScript, I was only used to creating apps for normal mobile phones. So I didn't know how to develop for a rugged PDA. After some research, I realized that the device I had to develop for was an Android-powered device.
That implied I could develop the same way I do for a standard Android mobile phone. NativeScript made this possible and I just want to provide a small tip on what was handy about it.
The key solution was to use Application.android.registerBroadcastReceiver
To receive the barcode scanned by the Android device in your NativeScript app, you can call the registerBroadcastReceiver
method on the Android application instance as follows:
const receiverCallback = (
context: android.content.Context,
intent: android.content.Intent
) => {
this.articleCode = '';
this.articleCode = intent.getStringExtra('DATA');
// could use any event bus
// just using a simple system setup I created
this.$emit('barcodeScanned', { barcode: this.articleCode });
};
Application.android.registerBroadcastReceiver(
'com.android.serial.BARCODEPORT_RECEIVEDDATA_ACTION',
receiverCallback
);
registerBroadcastReceiver
is the intent filter provided by the device manufacturer. The device I developed with was from Seypos and they provided the com.android.serial.BARCODEPORT_RECEIVEDDATA_ACTION
intent filter.Never did I think I would encounter a Rugged PDA for development in the field, but this simple and elegant yet extremely effective NativeScript snippet helped get the job done.
Sometimes short but sweet provides just the clarity you might be after in a crunch. Happy NativeScripting! 💙