简体   繁体   中英

Zxing android scan barcode, onActivityResult not calling

    @Override
public void onClick(View v) {
    if (v.getId() == R.id.scan_button) {
        Log.i("result", "START SCAN");
        IntentIntegrator scanIntegrator = new IntentIntegrator(
                BarcodeScan.this);
        scanIntegrator.initiateScan();

    }
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.startActivityForResult(intent, resultCode);
    Log.i("result", "Result Out");
    if (requestCode == 0) {
        IntentResult scanningResult = IntentIntegrator.parseActivityResult(
                requestCode, resultCode, intent);
        if (resultCode == RESULT_OK) {
            if (scanningResult != null) {
                String scanContent = scanningResult.getContents();
                DatabaseAdapter mDbHelper = new DatabaseAdapter(this);
                mDbHelper.createDatabase();
                mDbHelper.open();
                BookController bc = new BookController(mDbHelper.open());
                Log.i("result", scanContent);
                String bookID = bc.getBookIDByBarcode(scanContent);
                System.out.println(bookID);
                intent = new Intent(context, ReserveBook.class);
                intent.putExtra("BookID", bookID);
                startActivity(intent);
                this.finish();
            } else {
                Toast toast = Toast.makeText(getApplicationContext(),
                        "No scan data received!", Toast.LENGTH_SHORT);
                toast.show();
            }
        } else if (resultCode == RESULT_CANCELED) {
            // Handle cancel
            Log.i("App", "Scan unsuccessful");
        }
    }
}

I am implementing Zxing Barcode Scanning into my app, I am able to scan the barcode, but after scan the apps was stop. In the LogCat, the START SCAN got printed out. After that the app close.

Don't call super.startActivityForResult(intent, resultCode); Remove this line.

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