Hi,
I want to use Barcode scanner in Service, but scanner not receiving code. Please check this.
public class BarcodeService extends Service { private BarcodeScanner mBarcodeScanner; private BroadcastReceiver barcodeReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { BarcodeResult barcodeResult = new BarcodeResult(intent); if (barcodeResult.isBarcodeAction()) { String barcode = barcodeResult.getBarcode(); } } }; @Nullable @Override public IBinder onBind(Intent intent) { return null; } @Override public void onCreate() { super.onCreate(); mBarcodeScanner = new BarcodeScanner(this); registerBarcodeScanner(); Bundle extras = new Bundle(); extras.putBoolean(Intents.EXTRA_LED_ON, true); extras.putBoolean(Intents.EXTRA_SCAN_QR_CODE, false); extras.putBoolean(Intents.EXTRA_SCAN_1D_CODE, true); extras.putBoolean(Intents.EXTRA_SHOW_PREVIEW, false); extras.putInt(Intents.EXTRA_SCANNER_FACING, BarcodeScanner.BARCODE_SCANNER_FACING_CUSTOMER); mBarcodeScanner.executeStartScan(extras); } @Override public void onDestroy() { super.onDestroy(); unregisterBarcodeScanner(); } private void registerBarcodeScanner() { registerReceiver(barcodeReceiver, new IntentFilter(BarcodeResult.INTENT_ACTION)); } private void unregisterBarcodeScanner() { unregisterReceiver(barcodeReceiver); } }
Thank you.