I am using following code to invoke Barcode scanner apps 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 if Barcode scanner app is not installed and user has any other scanning app like google goggles i dont get desired result back.This breaks my application.
Is there any way in which i can prevent this ??
Yes. call Intent.setPackage()
with value "com.google.zxing.client.android". This will force it to only accept a response from Barcode Scanner.
Note however that this will make it impossible for other apps to respond, like Barcode Scanner+.