Problem with using Zxing through intent if Google glasses are installed

I use the following code to call barcode scanner applications from Zing

public Button.OnClickListener mScan = new Button.OnClickListener() { public void onClick(View v) { Intent intent = new Intent("com.google.zxing.client.android.SCAN"); intent.putExtra("SCAN_MODE", "QR_CODE_MODE"); startActivityForResult(intent, 0); } }; public void onActivityResult(int requestCode, int resultCode, Intent intent) { if (requestCode == 0) { if (resultCode == RESULT_OK) { String contents = intent.getStringExtra("SCAN_RESULT"); String format = intent.getStringExtra("SCAN_RESULT_FORMAT"); // Handle successful scan } else if (resultCode == RESULT_CANCELED) { // Handle cancel } } } 

The problem is that the barcode scanner application is not installed, and the user has another scanning application, such as google goggles, and I do not get the desired result back. This breaks my application.

Is there any way to prevent this?

+4
source share
2 answers

Yes. call Intent.setPackage() with the value "com.google.zxing.client.android". This will force him to accept only the response from the barcode scanner.

Please note that this does not allow other applications to respond, for example, Barcode Scanner +.

+6
source

It’s better to integrate a barcode scanner into your application. Zxing is an open source code that you can download from here . And for integration, please refer to this: http://www.falatic.com/index.php/12/building-zxing-for-android-part-3-using-eclipse . I think this will solve your problem.

0
source

Source: https://habr.com/ru/post/1380173/


All Articles