Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intent clash with PhoneGap apps #28

Closed
Eccenux opened this issue Jul 21, 2013 · 1 comment
Closed

Intent clash with PhoneGap apps #28

Eccenux opened this issue Jul 21, 2013 · 1 comment

Comments

@Eccenux
Copy link
Contributor

Eccenux commented Jul 21, 2013

The problem is the scan intent name is the same for all applications built with PhoneGap.

Reproducing:

  1. Build and install app on Android.
  2. Build and install different app (with different id in widget id) on the same device.
  3. Scan code.

Result:
Android will show a menu to choose application. This might be confusing to the user. Not a big issue if all apps use the same version of the plugin and phonegap. If apps use different versions and the user choose default action then every other app will fail.

Two places need changing:

  1. In plugin.xml:
    <action android:name="com.phonegap.plugins.barcodescanner.SCAN"/>
  2. In BarcodeScanner.java:
    SCAN_INTENT = "com.phonegap.plugins.barcodescanner.SCAN";

Problem is both should be changed to add application (widget) id. Not sure if plugman allows this.

@nusculus
Copy link

While adding the ability to restrict the allowed barcode formats (cuts down on read errors), aside from passing that option thru to zxing, I made these changes in my copy:

Within BarcodeScanner.java
import android.content.ComponentName; // added
private static final String SCAN_INTENT = "com.google.zxing.client.android.SCAN"; // changed
private static final String SCAN_CLASS = "com.google.zxing.client.android.CaptureActivity"; // added
private static final String ENCODE_INTENT = "com.google.zxing.client.android.ENCODE"; // changed
...
Intent intentScan = new Intent(SCAN_INTENT); // same
intentScan.setComponent(new ComponentName(this.cordova.getActivity().getApplicationContext(),SCAN_CLASS));
intentScan.addCategory(Intent.CATEGORY_DEFAULT); // same

in plugin.xml:
action android:name="com.google.zxing.client.android.SCAN"
and
action android:name="com.google.zxing.client.android.ENCODE"

and I restored the action checking code that Eccenux commented out in EncodeActivity.java

The zxing library is looking for the actions "com.google.zxing.client.android.SCAN" and "com.google.zxing.client.android.ENCODE" rather than "com.phonegap.plugins.barcodescanner.SCAN" and "ENCODE". Giving the specific component in the Intent prevents going to other apps that use the same library.

I'm new to plugins and Android. Expect that this can be done better or just plain done right. Please speak up if you see problems with this approach. After some field testing, I'll try to share the restricted format code too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants