@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中,START SCAN打印出来。之后应用关闭。
答案 0 :(得分:0)
不要调用super.startActivityForResult(intent,resultCode);删除此行。