簡體   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");
        }
    }
}

我正在將Zxing條碼掃描實施到我的應用程序中,能夠掃描條碼,但是在掃描后應用程序已停止。 在LogCat中,開始掃描已打印出來。 之后,該應用程序關閉。

不要調用super.startActivityForResult(intent,resultCode); 刪除此行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM