酒吧code Rearder Zxing [英] BarCode Rearder Zxing
问题描述
我要扫描QR codeS按钮点击,问题是当我在我的设备操作结果意向变量运行code总是返回0。
I want to Scan QR codes on button Click, problem is when I run code on my device Activity Result Intent variable always returns 0.
我如何知道吧code阅读器的工作?我目前看到的设备屏幕上的黄色小点。
How do I know if the barcode reader work? I currently see yellow dots on the device's screen.
下面是我的code:
private OnClickListener scanner = new OnClickListener() {
public void onClick(View v) {
IntentIntegrator.initiateScan(BarCodeScannerActivity.this);
}
};
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
if (scanResult != null) {
// handle scan result
String s = "http://www.google.com/search?q=";
s += scanResult.getContents();
Intent myIntent1 = new Intent(Intent.ACTION_VIEW, Uri.parse(s));
startActivity(myIntent1);
}
感谢
推荐答案
您在code误差
您应该有
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
if (result != null) {
String contents = result.getContents();
if (contents != null) {
showDialog(R.string.result_succeeded, result.toString());
} else {
showDialog(R.string.result_failed, getString(R.string.result_failed_why));
}
}
}
您不能覆盖的onActivityResult
如的onCreate
或在onStart
而你正在写的onActivityResult像这是最常见的错误通常的方法。
Rather you are writing onActivityResult like normal method which is most common mistake.
此外,如果你可以提到 integrator.initiateScan(IntentIntegrator.QR_ code_TYPES);
或 integrator.initiateScan(IntentIntegrator.PRODUCT_ code_TYPES);
这将是巨大的。
Also if you can mention integrator.initiateScan(IntentIntegrator.QR_CODE_TYPES);
or integrator.initiateScan(IntentIntegrator.PRODUCT_CODE_TYPES);
it would be great.
这篇关于酒吧code Rearder Zxing的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!