3

アプリでZXingバーコードスキャナーを使用したい。ScanningViaIntentは、このアプリがスキャンを統合するための良い方法だと思います。ただし、ユーザーがこのアプリを使用できるかどうかをランタイムで確認したいと思います。これを行う簡単な方法はありますか?または、AndroidManifest.xmlをチェックして、デバイスに必要な機能を確認し、ユーザーにPlayストアがインストールされているかどうかを確認する必要がありますか?

編集:それを明確にするためだけに; デバイスのサポートがあるかどうかをコードで知りたいと思いました。ScanningViaIntentは、インストールされていないアプリを適切に処理することを知っています。:)

4

4 に答える 4

2

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

于 2012-07-27T08:50:25.227 に答える
1

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 ^^

于 2012-07-27T08:45:39.507 に答える
1

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.

于 2012-07-27T08:50:33.143 に答える
1

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;
}
于 2012-07-27T08:55:23.233 に答える