Launching via Intent also "activates" Google Goggles

366 views
Skip to first unread message

Henrik Niehaus

unread,
Dec 16, 2011, 8:48:38 AM12/16/11
to zxing
Hi,

I'm using zxing in my app by Intent, like this:

private void launchScanner() {
Intent intent = new
Intent("com.google.zxing.client.android.SCAN");
try {
startActivityForResult(intent, REQUEST_CODE_SCANNER);
} catch (ActivityNotFoundException e) {
// ask the user, if he wants to install from market ...
}
}

If Barcode Scanner is not installed, the user is asked, if he wants to
install it. If he accpets, the market opens with Barcode Scanner
preselected. Calling Barcode Scanner via Intent and getting the result
works fine. I like this solution, because the apps are totally
decoupled and the user receives updates for Barcode Scanner
automatically. I as a developer don't have to care / update my app
each time Barcode Scanner gets updated.

Now Google Goggles comes in. I noticed, that Google Goggles reacts on
my Intent call, too. Though my call contains the fully qualified name.
So, if I have Barcode Scanner and Goggles installed, and launch the
scanner, I get a selection dialog with both apps. This is acceptable,
if you want to scan codes, which are supported by Goggles. In my case
I have interleaved 2/5, which Goggles doesn't seem to recognize. So
Googles isn't a real alternative to Barcode Scanner and shouldn't show
up in the selection.

So my question is, is there a way to make 100% sure, that only Barcode
Scanner is taken into account, when launching the scan process?

BR
Henrik

Henrik Niehaus

unread,
Dec 16, 2011, 11:03:01 AM12/16/11
to zxing
Ok, figured it out myself. You have to specify the package name, too:

private void launchScanner() {
Intent intent = new Intent(BARCODE_SCANNER_PACKAGE + ".SCAN");
intent.setPackage(BARCODE_SCANNER_PACKAGE);


try {
startActivityForResult(intent, REQUEST_CODE_SCANNER);
} catch (ActivityNotFoundException e) {
// ask the user, if he wants to install from market ...
}
}

On 16 Dez., 14:48, Henrik Niehaus <henrik.nieh...@googlemail.com>
wrote:

Sean Owen

unread,
Dec 16, 2011, 12:10:03 PM12/16/11
to zx...@googlegroups.com
Better still take a look at the latest version of the code in Subversion under android-integration/. It pre-packages all of this logic for you, including restricting to only certain apps.

Ajay Thomas

unread,
Dec 27, 2011, 11:50:26 PM12/27/11
to zx...@googlegroups.com
Hi

I have this same problem. Without writing the setPackage line, it uses Google Goggles.
So, I also wrote similar code to the one Henrik posted the second time with Intent.setPackage.


 Button scanner = (Button)findViewById(R.id.scanner);
            scanner.setOnClickListener(new OnClickListener() {
               
                public void onClick(View v) {
                                    
                    if (isIntentAvailable(AndroidScanner.this, "com.google.zxing.client.android.SCAN")) {            
                    Intent intent = new Intent("com.google.zxing.client.android.SCAN");
                    intent.setPackage("com.google.zxing.client.android");
                    intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
                    startActivityForResult(intent, 0);
                      } else {
                        Dialog confirmScannerInstall = new AlertDialog.Builder( AndroidScanner.this )
                          .setIcon( R.drawable.icon )
                          .setTitle( getString( R.string.app_name ) )
                          .setMessage( "The Barcode reader is not present - install it now?")
                          .setPositiveButton( "Yes", new DialogInterface.OnClickListener() {
                            public void onClick( DialogInterface dialog, int whichButton ) {
                              Uri uri = Uri.parse("market://search?q=pname:com.google.zxing.client.android");                        
                              Intent installIntent = new Intent(Intent.ACTION_VIEW, uri);
                              startActivity(installIntent);
                            }
                          })
                          .setNeutralButton("No" , new DialogInterface.OnClickListener() {
                            public void onClick( DialogInterface dialog, int whichButton ) {
                              return;
                            }
                          })                
                          .create();
                        confirmScannerInstall.show();
                      }
 
                    startActivityForResult(intent, 0);
                }


However, the app does not give a dialog if Barcode Scanner is not installed. I think this is because of the setPackage line. Instead, it just crashes.
Any suggestions?

Thank you

P.S:Without that line and if neither Goggles nor Barcode Scanner is installed, then dialog appears.
Reply all
Reply to author
Forward
0 new messages