У меня есть считыватель штрих-кода Newland MT90 android mobile. Я создаю приложение, в котором я хочу сканировать два штрих-кода. Когда я запускаю свой код и нажимаю любую кнопку в первый раз, она работает нормально. В то же время, когда я нажимаю другую кнопку, он заменяет штрих-код в обоих TextView. Как я могу решить эту проблему?
btnScanUid.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
intent = new Intent("nlscan.action.SCANNER_TRIG");
intent.putExtra("SCAN_TIMEOUT", 4); // SCAN_TIMEOUT value: int, 1-9; unit: second
intent.putExtra("SCAN_TYPE ", 1); // SCAN_TYPE: read one barcodes during a scan attempt
//sendBroadcast(intent);
ReadUID(intent);
}
});
btnScanPart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent("nlscan.action.SCANNER_TRIG");
intent.putExtra("SCAN_TIMEOUT", 4); // SCAN_TIMEOUT value: int, 1-9; unit: second
intent.putExtra("SCAN_TYPE ", 1); // SCAN_TYPE: read one barcodes during a scan attempt
//sendBroadcast(intent);
ReadPart(intent);
}
});
public void ReadUID(Intent intent){
sendBroadcast(intent);
registerReceiver(new BroadcastReceiver() {
@Override public void onReceive(Context context, Intent intent) {
if (intent != null) {
barcode = intent.getStringExtra("SCAN_BARCODE1");
int barcodeType = intent.getIntExtra("SCAN_BARCODE_TYPE", -1);
if(barcode!=null) {
UidBarcode.setText(barcode);
UidBarcodeType.setText(String.valueOf(barcodeType));
String text=String.valueOf(barcodeType); // Whatever you need to encode in the QR code
MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
try {
BitMatrix bitMatrix = multiFormatWriter.encode(text, BarcodeFormat.QR_CODE,200,200);
BarcodeEncoder barcodeEncoder = new BarcodeEncoder();
Bitmap bitmap = barcodeEncoder.createBitmap(bitMatrix);
UidImageView.setImageBitmap(bitmap);
} catch (WriterException e) {
e.printStackTrace();
}
}else{
Toast.makeText(getApplicationContext(), "Barcode Not getting.", Toast.LENGTH_LONG).show();
}
} else {
Toast.makeText(getApplicationContext(), "Scan Failed", Toast.LENGTH_LONG).show();
}
}
}, new IntentFilter("nlscan.action.SCANNER_RESULT"));
}
public void ReadPart(Intent intent){
sendBroadcast(intent);
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent != null) {
barcodePart = intent.getStringExtra("SCAN_BARCODE1");
int barcodeType = intent.getIntExtra("SCAN_BARCODE_TYPE", -1);
if(barcodePart!=null) {
PartBarcode.setText(barcodePart);
PartBarcodeType.setText(String.valueOf(barcodeType));
String text=String.valueOf(barcodeType); // Whatever you need to encode in the QR code
MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
try {
BitMatrix bitMatrix = multiFormatWriter.encode(text, BarcodeFormat.QR_CODE,200,200);
BarcodeEncoder barcodeEncoder = new BarcodeEncoder();
Bitmap bitmap = barcodeEncoder.createBitmap(bitMatrix);
PartImageView.setImageBitmap(bitmap);
} catch (WriterException e) {
e.printStackTrace();
}
}else{
Toast.makeText(getApplicationContext(), "Barcode Not getting.", Toast.LENGTH_LONG).show();
}
} else {
Toast.makeText(getApplicationContext(), "Scan Failed", Toast.LENGTH_LONG).show();
}
}
}, new IntentFilter("nlscan.action.SCANNER_RESULT"));
}