gpt4 book ai didi

android - 将 QR 扫描器集成到 Android 应用程序

转载 作者:行者123 更新时间:2023-11-29 20:54:20 24 4
gpt4 key购买 nike

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

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

此外,我尝试了几个博客(How to Create QR Codes with an Android PhoneZXing 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,并且扫描仪将在您的应用程序中。

附言必须将此代码放在标签内的 list 文件中:

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

关于android - 将 QR 扫描器集成到 Android 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28212660/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com