[英]Android Intent to Google Goggles always results in RESULT_CANCELLED. How do I bring back a legitimate result to my Activity?
So, I've been trying to use the Google Goggles Intent, so I can use the scanner as an OCR device. 因此,我一直在尝试使用Google Goggles Intent,因此可以将扫描仪用作OCR设备。 I've used the following code in my Activity:
我在“活动”中使用了以下代码:
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
//intent.setPackage("com.google.zxing.client.android");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
Log.d("TAG", "start goggles!");
startActivityForResult(intent, 0);
And as for my onActivityResult, it looks like this : 至于我的onActivityResult,它看起来像这样:
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");
Log.d("TAG", "result back!"+contents);
Toast.makeText(getBaseContext(), contents, Toast.LENGTH_LONG).show();
} else if (resultCode == RESULT_CANCELED) {
Toast.makeText(getBaseContext(), "CANCELLED", Toast.LENGTH_LONG).show();
// TODO: Handle cancel
}
}
}
The above code successfully starts the other application but fails to bring back the result and always ends up in the RESULT_CANCELLED resultCode. 上面的代码成功启动了另一个应用程序,但未能带回结果,并且始终以RESULT_CANCELLED resultCode结尾。 ( I'm using the back button to return to my application, am I doing anything wrong here?)
(我使用后退按钮返回到我的应用程序,我在这里做错了吗?)
Any help would be appreciated. 任何帮助,将不胜感激。 Thanks!
谢谢!
Well, if you use the back button to return to your app, of course the resultCode
will be RESULT_CANCELED
, because you literally cancelled the Goggles request. 好吧,如果您使用“后退”按钮返回到您的应用,那么
resultCode
当然将是RESULT_CANCELED
,因为您实际上取消了Goggles请求。 If you scan a valid qr code while in Googles, it should automatically close and return to your Activity with RESULT_OK
. 如果您在Google中扫描有效的二维码,则该代码应自动关闭并使用
RESULT_OK
返回到“活动”。
Note that if you start Goggles for the first time, it will show a tutorial and ask for some intial settings. 请注意,如果您是首次启动Goggles,它将显示一个教程并要求一些初始设置。 When this appears, it will NOT return to your app after scanning the qr code.
当出现这种情况时,扫描二维码后它将不会返回您的应用程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.