简体   繁体   中英

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

    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 . It is easy to use. See Here .

**Include the core.jar file on the build path.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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