如果安装了 google goggles,则通过 Intent 使用 Zxing 时出现问题
我正在使用以下代码从 Zing 调用条形码扫描仪应用程序。
public Button.OnClickListener mScan = new Button.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
}
};
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
// Handle successful scan
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
}
}
问题是,如果未安装条形码扫描仪应用程序并且用户有任何其他扫描应用程序(如 google goggles),我将无法得到所需的结果。这会破坏我的应用程序。
有什么办法可以防止这种情况发生吗?
I am using following code to invoke Barcode scanner apps from Zing
public Button.OnClickListener mScan = new Button.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
}
};
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
// Handle successful scan
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
}
}
The problem is if Barcode scanner app is not installed and user has any other scanning app like google goggles i dont get desired result back.This breaks my application.
Is there any way in which i can prevent this ??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的。使用值“com.google.zxing.client.android”调用
Intent.setPackage()
。这将迫使它只接受来自条形码扫描仪的响应。但请注意,这将使其他应用程序无法响应,例如 Barcode Scanner+。
Yes. call
Intent.setPackage()
with value "com.google.zxing.client.android". This will force it to only accept a response from Barcode Scanner.Note however that this will make it impossible for other apps to respond, like Barcode Scanner+.
最好将条形码扫描仪集成到您的应用程序中。 Zxing 是一个开源代码,您可以从此处下载。对于集成,请参阅:http://www.falatic.com/index.php/12/building-zxing-for-android-part-3-using-eclipse。我认为这会解决你的问题。
its better to integrate the bar code scanner to your app. Zxing is an open source code you can download it from here. And for the Integration please refer this: http://www.falatic.com/index.php/12/building-zxing-for-android-part-3-using-eclipse. I think this will solve your issue.