I have been asked to look into replacing a customer's current handheld software and devices (Windows CE 7) with android (like Tera P172 + also use on company mobiles). I want to be able to use the barcode scanner and not the camera currently, but may look at using either with a setting to determine which one to use. I want to use .Net MAUI but am not completely sure of the best way to read the barcode. It will only be for certain pages where it will prompt for a barcode, wait for the barcode before moving on from there. I have seen articles on using a BroadcastReceiver, but am not completely sure of how to use it and wire it into the required views/popups?
Any help would be much appreciated...
Ade
I have tried using a BroadcastReceiver, but I am struggling to find the correct IntentFilter and KeyValueName?
Thanks. I had the wrong IntentFilter name and KeyValue to get the barcode out of the Intent.
public class MainActivity : MauiAppCompatActivity
{
private readonly BroadcastReceiver _barcodeReceiver = new BarcodeBroadcastReceiver();
protected override void OnResume()
{
base.OnResume();
RegisterReceiver(_barcodeReceiver, new IntentFilter("com.scanner.broadcast"));
}
protected override void OnPause()
{
UnregisterReceiver(_barcodeReceiver);
base.OnPause();
}
}
public class BarcodeBroadcastReceiver : BroadcastReceiver
{
public override async void OnReceive(Context context, Intent intent)
{
var barcode = intent.GetStringExtra("data");
}
}