通过 Intent 进行 ZXing 集成问题
好吧,我正在尝试实现 zxing 与我的 Android 应用程序的集成。在我的应用程序中有一个 MainActivity。在此 MainActivity 中,我使用按钮来执行下面的第一段代码。但是每次执行第一个代码块并且应用程序读取二维码时,我都会在第二个代码块中收到结果代码 RESULT_CANCELED 值。一旦 ZXing Activity 打开,就会执行第二个块。我做错了什么?
第一个代码块
Intent intent1 = new Intent("com.google.zxing.client.android.SCAN");
intent1.setPackage("com.google.zxing.client.android");
intent1.putExtra("SCAN_MODE", "ONE_D_MODE");
startActivityForResult(intent1, 0);
第二个代码块
public void onActivityResult(int requestCode, int resultCode, Intent intent2) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents2 = intent2.getStringExtra("SCAN_RESULT");
String format2 = intent2.getStringExtra("SCAN_RESULT_FORMAT");
EditText assetMon1 = (EditText) findViewById(R.id.assetMon1);
assetMon1.setText(contents2);
} else if (resultCode == RESULT_CANCELED) {
// Every time I receive this code
}
}
}
Well, I'm trying implement a integration of zxing with my Android App. In my app there is a MainActivity. In this MainActivity, I use a button to execute the first block of code below. But every time when execute the first block of code and the app read the QR Code, I receive as resultCode the value RESULT_CANCELED in the second block. The second block is executed as soon as the ZXing Activity is opened. What do I doing wrong?
First Block of Code
Intent intent1 = new Intent("com.google.zxing.client.android.SCAN");
intent1.setPackage("com.google.zxing.client.android");
intent1.putExtra("SCAN_MODE", "ONE_D_MODE");
startActivityForResult(intent1, 0);
Second block of code
public void onActivityResult(int requestCode, int resultCode, Intent intent2) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents2 = intent2.getStringExtra("SCAN_RESULT");
String format2 = intent2.getStringExtra("SCAN_RESULT_FORMAT");
EditText assetMon1 = (EditText) findViewById(R.id.assetMon1);
assetMon1.setText(contents2);
} else if (resultCode == RESULT_CANCELED) {
// Every time I receive this code
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我的应用程序中有非常相似的代码。唯一显着的区别是我有“PRODUCT_MODE”而不是“ONE_D_MODE”。
I have very similar code in my app. The only significant difference is that I have "PRODUCT_MODE" instead of "ONE_D_MODE".
遵循 在
android-integration
下的项目中提供了示例代码。只需调用此类中的方法,而不是调试您自己的版本。我认为使用 requestCode 0 最有可能是问题所在,但我猜测。它应该是请求的一种唯一 ID。但是 0 可能会被其他东西使用,并且您确实听到了对其他东西的响应。Follow the sample code provided in the project under
android-integration
. Just call the methods in this class rather than debug your own version. I think using requestCode 0 is most likely to be the problem, but I'm guessing. It is supposed to be a sort of unique ID for the request. But 0 might be used by something else and you're really hearing a response to something else.