简体   繁体   English

Zxing android扫描条形码,onActivityResult不调用

[英]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. 我正在将Zxing条码扫描实施到我的应用程序中,能够扫描条码,但是在扫描后应用程序已停止。 In the LogCat, the START SCAN got printed out. 在LogCat中,开始扫描已打印出来。 After that the app close. 之后,该应用程序关闭。

Don't call super.startActivityForResult(intent, resultCode); 不要调用super.startActivityForResult(intent,resultCode); Remove this line. 删除此行。

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

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