Search code examples
javaandroidzxingandroid-libraryandroid-inflate

Android: Avoiding "complete action using" when there's an app on the phone with the same pkg name as the library


I'm using ZXing, the barcode scanning library. It's also an app that you can download and install independantly, but I am currently using it as a library to integrate into my app. I want to be able to invoke that library and bring up one of its activities. In order to do so I use 'intent' and 'startactivityforresult' in which I declare the package name 'com.google.zxing.client.android'. In doing so it prompts me with the ability to choose between the installed stand alone barcode app, or my app. I need to circumvent that dialog so that it will just choose my app by default. It's interesting because I believe the reason I can't use normal methods to bypass that 'complete action using' dialog is that the app has the same package name as the library that I'm using. Any assistance would be appreciated. If you require code or pictures then I'll post it but I believe that I've provided enough information.


Solution

  • If you're able to define the calling Intent contents it's easy - just give it custom string pointing to your activity.

    Intent intent = new Intent("com.yourapp.package.SOME_ACTION")
    

    And register the action in manifest:

    <activity android:name=".package.CalledActivity">
        <intent-filter>
            <action android:name="com.yourapp.package.SOME_ACTION"/>
        </intent-filter>
    </activity>
    

    Your activity may extend library's activity to do the job.

    If you're not able to influence sent Intent me thinks it's not possible to circumvent chooser dialog, except a) uninstalling apps which handle com.google.zxing.client.android so there's only one left b) user chooses your app to handle Intent "Always", not "Just Once".