So, I've been trying to use the Google Goggles Intent, so I can use the scanner as an OCR device. 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 :

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. ( I'm using the back button to return to my application, am I doing anything wrong here?)

Any help would be appreciated. Thanks!

1

There are 1 best solutions below

6
On

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. If you scan a valid qr code while in Googles, it should automatically close and return to your Activity with RESULT_OK.

Note that if you start Goggles for the first time, it will show a tutorial and ask for some intial settings. When this appears, it will NOT return to your app after scanning the qr code.