我的条形码扫描仪读取qr代码但不是1d条码android

时间:2016-08-10 11:51:09

标签: android

这是我的活动,我使用意图调用相机活动,我使用了谷歌播放服务中引入的条形码dector类Mobilevision请帮我找到我缺少的地方

    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());
        }
    }
}

1 个答案:

答案 0 :(得分:0)

有一个开源库。 Download BarcodeFragLib2。它很容易使用。见Here

**在构建路径中包含core.jar文件。