机器人:zxing吧code扫描成功,但是从活动没有返回 [英] android: zxing barcode scan successful but not returning from activity
问题描述
我成功地利用zxing扫描codeS,通过调用安装吧code读者的意图,但是当它发出蜂鸣声,并表示了良好的扫描我希望zxing活动将返回控制,所以我可以处理结果,但坐在那里,并尝试重新扫描。我要preSS后退按钮和然后的返回,我可以做下一步。有一些明显的标志,我很想念我的时候调用扫描仪?
任何建议感激地接受。非常感谢。
下面是我的code:
公共布尔的onTouchEvent(最终MotionEvent事件){
意向意图=新的意图(com.google.zxing.client.android.SCAN);
intent.putExtra(com.google.zxing.client.android.SCAN.SCAN_MODE,QR_ code_MODE);
startActivityForResult(意向,0);
返回true;
}
公共无效onActivityResult(INT申请code,INT结果code,意图意图){
super.onActivityResult(要求code,因此code,意图);
如果(要求code == 0){
如果(结果code == RESULT_OK){
字符串内容= intent.getStringExtra(SCAN_RESULT);
字符串格式= intent.getStringExtra(SCAN_RESULT_FORMAT);
//处理成功的扫描
字符串s =http://www.google.com/search?q=;
S + =内容;
意图myIntent1 =新的意图(Intent.ACTION_VIEW,Uri.parse(S));
startActivity(myIntent1);
}
其他
如果(结果code == RESULT_CANCELED){
//处理取消
}
}
}
}
为什么不使用所提供的 IntentIntegrator
类?这是在项目文档中提到的唯一办法,你看看那些? HTTP://$c$c.google.com/p/zxing/wiki / ScanningViaIntent
我创造了它包裹起来发送和解析意向的这些细节,所以你不把错别字。例如,有没有这样的东西作为额外的com.google.zxing.client.android.SCAN.SCAN_MODE。
I am successfully using zxing to scan codes, by calling the installed barcode reader's intent, but when it beeps and indicates a good scan I expect the zxing activity would return control so I can process the result, but it sits there and tries to scan again. I have to press the back button and then it returns and I can do the next step. Is there some obvious flag I'm missing when I call the scanner?
Any advice gratefully received. Many thanks.
Here's my code:
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
}
}
}
}
Why not use the provided IntentIntegrator
class? This is the only approach mentioned in the project docs, did you have a look at those? http://code.google.com/p/zxing/wiki/ScanningViaIntent
I created it to wrap up these details of sending and parsing the Intent, so you don't make typos. For example, there's no such thing as extra "com.google.zxing.client.android.SCAN.SCAN_MODE".
这篇关于机器人:zxing吧code扫描成功,但是从活动没有返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!