簡體   English   中英

我的條形碼掃描儀讀取二維碼,但不讀取一維條形碼android

[英]my barcode scanner reading qr codes but not 1d barcode android

這是我的活動,我使用意圖來調用攝像機活動,並且我使用了Google Play服務中引入的Barcode dector類Mobilevision pls幫助我找到我缺少的地方

    public class MainActivity extends AppCompatActivity {

    BarcodeDetector detector;
    public void scanBarcode(View view){
        try {
            //detector = new BarcodeDetector.Builder(getApplicationContext()).setBarcodeFormats(Barcode.DATA_MATRIX | Barcode.QR_CODE).build();
            detector = new BarcodeDetector.Builder(getApplicationContext()).setBarcodeFormats(0).build();
            if (!detector.isOperational())
                Toast.makeText(MainActivity.this, "Error Occured Please Assure to Have Play Services", Toast.LENGTH_LONG).show();
            else {
                Toast.makeText(MainActivity.this, "Done", Toast.LENGTH_LONG).show();
                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                startActivityForResult(intent, 0);

            }
        }catch (Exception e){
            Toast.makeText(MainActivity.this,"Eror"+e.getMessage(),Toast.LENGTH_LONG).show();
        }

    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

    }

    @Override
    protected void onActivityResult(int requestCode,int replyCode,Intent data){
        TextView textView = (TextView) findViewById(R.id.ContentWillAriveHere);
        try {
            Bitmap myBitmap = (Bitmap) data.getExtras().get("data");
            Frame frame = new Frame.Builder().setBitmap(myBitmap).build();
            SparseArray<Barcode> barcode = detector.detect(frame);

            Barcode barcode1 = barcode.valueAt(0);

            textView.setText("Data = "+barcode1.rawValue);
        }catch (Exception e){
            textView.setText("Data = "+e.getMessage());
        }
    }
}

為此有一個開源庫。 下載BarcodeFragLib2 這個用起來很簡單。 這里

**在構建路徑中包括core.jar文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM