0
@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中,開始掃描打印出來。之後,該應用程序關閉。Zxing android掃描條形碼,onActivityResult不會調用
同樣的結果,掃描應用程序關閉後。 – user3687053 2014-11-02 06:41:49
刪除該行後,您是否至少會看到Log.i(「result」,「Result Out」);打印在您的調試控制檯上? – 2014-11-02 13:27:27
刪除除了Log.i(「result」,scanContent)之外的所有內容if(scanningResult!= null){}聲明。可能是您的ReserveBook活動沒有像您那樣開始,或者數據庫未打開。反正,如果你能看到Log.i(「result」,「Result Out」);和Log.i(「result」,scanContent);打印出來,那麼你可以聲稱onActivityResult()被正確調用。 – 2014-11-02 13:32:47