简体   繁体   English

将Android Intent用于Google Goggles始终会导致RESULT_CANCELLED。 如何将合法结果带回我的活动?

[英]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.

相关问题 Android on活动结果始终返回0和空意图 - Android on activity result always return 0 and null intent 如果我想知道结束时间但不需要结果或不在乎它是否被取消,该如何启动android活动? - How do I start an android activity if I want to know when it's over but I don't need a result or care if it was cancelled? 对于Intent.ACTION_SEND,StartActivityForResults始终返回RESULT_CANCELLED - StartActivityForResults always returns RESULT_CANCELLED for Intent.ACTION_SEND 在Android中,如何测试取决于另一个活动结果的活动? - In Android, how do I test an activity that depends on the result of another activity? 结果代码始终为0,因为卸载了Android中的Intent - Result Code is always 0 as result of uninstallation Intent in android 广播意图回调:result = CANCELLED - broadcast intent callback: result=CANCELLED Android Google 登录返回 RESULT_CANCELLED - Android Google sign in returns RESULT_CANCELLED 如何将意图结果数据发送到后面的2个活动(跳过先前的活动)? - How do I send Intent Result Data to 2 Activity behind (skipping previous activity)? 尽管手动将结果设置为 RESULT_OK,但活动始终返回 RESULT_CANCELLED - Activity always returns RESULT_CANCELLED despite manually setting the result as RESULT_OK 如何将现有活动从服务带回前台? - How do I bring an existing activity back to the front from a service?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM