Newland MT90如何读取多个条码?

How to read multiple Bar Code from Newland MT90?

我有一个新大陆 MT90 条码 reader android 手机。我正在创建一个应用程序,我想在其中扫描两个条形码。当我 运行 我的代码并且我第一次按下任何按钮时它工作正常。同时,当我按下另一个按钮时,它正在替换两个 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"));
}

假设返回相同的 Intent,您只需更改发出的 Intent

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

// passing the resId:
intent.putExtra("SCAN_TARGET_FIELD", R.id.btnScanUid);

ReadUID(intent);

然后决定.onReceive()更新哪个字段。