Roy Solberg
Roy Solberg

Reputation: 19673

Easiest way to check for ZXing support?

I want an app to use ZXing barcode scanner. I think the ScanningViaIntent is a good way for this app to integrate the scanning. However, I would like to runtime know if the user is able to use this app or not. Is there a simple way to do this? Or should I now and then check their AndroidManifest.xml to see what the required features for a device are + check if the user has Play Store installed?

EDIT: Just to make it clear; I wanted to in code know if there was device support. I know the ScanningViaIntent handles the app not being installed very well. :)

Upvotes: 3

Views: 1237

Answers (4)

paulkayuk
paulkayuk

Reputation: 1052

The ZXing team have provided a small library of code to handle this scenario elegantly, including prompting the user to download the ZXing barcode scanner if they do not already have it installed.

The details and download link can be found here:

I realise such linking is frowned upon here, but other than wholly duplicating the information from the linked site and posting the full content of the provided library, I couldn't see how else to adequately answer the question. Any advice on how to would be appreciated

EDIT: Apologies, I should have checked the links in the OPs question and seen that he was already aware of the IntentIntegrator code libary for ZXing

Upvotes: 2

Roy Solberg
Roy Solberg

Reputation: 19673

This is how I ended up doing. At least until I find a better way. :)

/**
 * Convenience method for checking for ZXing app support. Requirements found
 * in http://code.google.com/p/zxing/source/browse/trunk/android/AndroidManifest.xml 
 * and
 * http://code.google.com/p/zxing/source/browse/trunk/android-integration/src/com/google/zxing/integration/android/IntentIntegrator.java
 * .
 * 
 * @return boolean true if app is supported, false if not.
 */
protected boolean hasSupportForZxing() {
    PackageManager packageManager = getPackageManager();
    if(!packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA)){ // ZXing required away faced camera
        return false;
    }
    if(!packageManager.hasSystemFeature(PackageManager.FEATURE_SCREEN_LANDSCAPE)){ // ZXing requires landscape mode
        if(packageManager.hasSystemFeature(PackageManager.FEATURE_SCREEN_PORTRAIT)){ // PackageManager doc states that if both landscape and portrait support is missing then both are probably supported (compatibility reasons)
            return false;
        }
    }
    if(!isMarketUrisHandled()){
        return false;
    }
    return true;
}

protected boolean isMarketUrisHandled() {
    Intent marketIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=dummy"));
    List<ResolveInfo> resolveInfos = getPackageManager().queryIntentActivities(marketIntent, 0);
    return resolveInfos.size() > 0;
}

Upvotes: 1

Alexander
Alexander

Reputation: 48262

Perhaps you can do something like initiateScan method in the ZXing client

http://code.google.com/p/zxing/source/browse/trunk/android-integration/src/com/google/zxing/integration/android/IntentIntegrator.java

it prompts to download ZXing if it's not installed.

Upvotes: 1

Climbatize
Climbatize

Reputation: 1123

Yes, I think you should check if the user has a camera, or maybe other things like auto-focus. For some of my projects I had to integrate ZXing directly into the project to avoid this kind of problems.

But after all, some cases just telling the user that he must have a minimum requirement to use the scanning function can be enough ^^

Upvotes: 1

Related Questions