简体   繁体   English

我的条形码扫描仪读取二维码,但不读取一维条形码android

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

this is my activity i use intent to call camera actvity and i have used Barcode dector class introduced in google play services Mobilevision pls help me to find where i am lacking 这是我的活动,我使用意图来调用摄像机活动,并且我使用了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());
        }
    }
}

there is an open source library for this. 为此有一个开源库。 Download BarcodeFragLib2 . 下载BarcodeFragLib2 It is easy to use. 这个用起来很简单。 See Here . 这里

**Include the core.jar file on the build path. **在构建路径中包括core.jar文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM