我通过调用已安装的条形码阅读器的意图成功地使用 zxing 扫描代码,但是当它发出哔哔声并表示扫描良好时,我希望 zxing 活动会返回控制,以便我可以处理结果,但它坐在那里并尝试再次扫描. 我必须按下后退按钮,然后它会返回,我可以进行下一步。当我打电话给扫描仪时,我是否缺少一些明显的标志?
感激地收到任何建议。非常感谢。
这是我的代码:
public boolean onTouchEvent(final MotionEvent event) {
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("com.google.zxing.client.android.SCAN.SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
return true;
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
// Handle successful scan
String s = "http://www.google.com/search?q=";
s += contents;
Intent myIntent1 = new Intent(Intent.ACTION_VIEW, Uri.parse(s));
startActivity(myIntent1);
}
else
if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
}
}
}