将 QR 扫描仪集成到 Android 应用

Integrating QR scanner to Android app

我正在为我的客户开发一个 android 应用程序,他要求在该应用程序中内置 QR 扫描仪。所以,我不希望用户必须从 GooglePlay 下载另一个应用程序。换句话说,我不想从我的应用程序调用另一个应用程序 QR 扫描仪。我需要在我的应用程序中内置 QR 扫描仪。

我已经在 github 和此处的 Whosebug 上阅读了有关 ZXing 的信息。以我的理解,将其 QR 扫描仪集成到应用程序中并不是一个好主意。最好通过 Intent(或所谓的 IntegratedIntent)调用扫描仪,然后再次调用另一个扫描仪应用程序(?),该应用程序必须先前从 GoolePlay 下载,我不希望那样。

此外,我尝试了几个博客 (How to Create QR Codes with an Android Phone, ZXing QR Reader Direct Integration) 中的一些想法并且效果很好。

是否有可能以某种方式内置已经开发的 QR 扫描仪?

好吧,我找到了解决方案。问题是这样的: 出于某种原因,我正在使用 IntentIntegrator:

IntentIntegrator integrator = new IntentIntegrator(MainActivity.this);
integrator.initiateScan(IntentIntegrator.QR_CODE_TYPES);

如果您使用 IntentIntegrator,即使您将 CaptureActivity 项目作为库添加到您的项目中,iw 也会请求在设备上安装 BarCode 扫描器应用程序。

我改用了这个,它可以工作 gr8。

Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);

它将从 CaptureActivity 项目启动 CaptureActivity,扫描仪将在您的应用程序中。

P.S。必须将此代码放在标签内的清单文件中:

<activity
            android:name="com.google.zxing.client.android.CaptureActivity"
            android:configChanges="orientation|keyboardHidden"
            android:screenOrientation="landscape"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
            android:windowSoftInputMode="stateAlwaysHidden" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
            <intent-filter>
                <action android:name="com.google.zxing.client.android.SCAN" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>