Android 条码重新整理器
我想在点击按钮时扫描二维码,问题是当我在我的设备上运行代码时,Activity Result Intent变量始终返回0 如何知道条形码阅读器是否工作?我目前在设备屏幕上看到黄点 这是我的密码:Android 条码重新整理器,android,Android,我想在点击按钮时扫描二维码,问题是当我在我的设备上运行代码时,Activity Result Intent变量始终返回0 如何知道条形码阅读器是否工作?我目前在设备屏幕上看到黄点 这是我的密码: private OnClickListener scanner = new OnClickListener() { public void onClick(View v) { IntentIntegrator.initiateScan(BarCodeScannerActivity
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);
}
谢谢您的代码有错误
你应该
@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));
}
}
}
您没有像onCreate
或onStart那样覆盖onActivityResult
相反,你是在写活动结果,就像正常的方法一样,这是最常见的错误
另外,如果您可以提及integrator.initiateScan(IntentIntegrator.QR\u代码类型)代码>或积分器.initiateScan(管理积分器.产品代码类型)
那太好了。您可能想看看这个,您可能需要向initiateScan添加更多参数:我没有使用IntentIntegrator,所以不确定使用该方法的最佳方法。integrator.initiateScan(IntentIntegrator.QR\u code\u类型);给出错误它只接受活动名称我对此很生气,然后你发了一篇关于@override
,大帮助和启动扫描(IntentIntegrator.PRODUCT\u code\u TYPES)的帖子代码>工作正常,但请记住,当您提供参数时,它不会返回任何内容