gpt4 book ai didi

android - 用于 phonegap android 的 Zxing 条码扫描器插件不适用于只有前置摄像头的 nexus 7

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:23:36 25 4
gpt4 key购买 nike

哪个适用于 phonegap android 的条码扫描器插件也适用于前置摄像头?

最佳答案

要使 Cordova/PhoneGap BarcodeScanner 插件正常工作,您需要比使用大多数其他插件更进一步。

我的大部分工作都是在 Eclipse 之外进行的,所以我将解释如何从终端完成这项工作,如果您需要它们,我将添加 Eclipse 注释(尽管询问。)

克隆插件项目

如果您还没有,请从 github 获取 phonegap-plugins 项目:

git clone git://github.com/phonegap/phonegap-plugins.git 

(我们假设它们被克隆到:/home/mike/phonegap-plugins)

我们还假设您的项目名为 /home/mike/CordovaProject出于此答案的目的。

然后复制/home/mike/phonegap-plugins/Android/BarcodeScanner/2.2.0/LibraryProject的内容进入/home/mike/BarcodeLibrary

这将包含 zxing 库项目作为可用 Activity ,检查您是否有 AndroidManifest.xml, ant.properties, assets, bin...等里面/home/mike/BarcodeLibrary .

我已经用 Nexus 7 对此进行了检查,插件中包含的 zxing 库代码工作正常。 (zxing 2.1 不是 2.2)

可以在 src/com/google/zxing... 处替换 zxing 库代码使用 2.2 下载的代码,但这是不必要的,需要额外的工作/测试。

更新库以使用 Android SDK

您需要更新 /home/mike/BarcodeLibrary项目使用

android update project /home/mike/BarcodeLibrary

如果您需要指定一个目标(SDK 版本),您可以获得一个列表:android list target

顺便说一下,这假设您已经安装了 android sdk。从http://developer.android.com/sdk/获取

如果出现问题,请确保您已复制 LibraryProject 的内容进入BarcodeLibrary

更新您的项目

现在您可以更新项目以使用 BarcodeLibrary .将这些复制到您的项目中:

phonegap-plugins/Android/BarcodeScanner/2.2.0/assets/www/barcodescanner.js
phonegap-plugins/Android/BarcodeScanner/2.2.0/src/com/phonegap/plugins/barcodescanner/BarcodeScanner.java

进入assets/wwwsrc/com/phonegap/plugins/barcodescanner分别。

项目属性/库引用

现在您需要更新 project.properties包括 BarcodeLibrary , 编辑它以包含新行:

android.library.reference.1=../BarodeLibrary/

(如果您有更多的库要引用,您会为它们编号,以允许对编译依赖项进行排序。)

请注意,如果您想将库直接包含到您的主项目中,您可以将它复制到一个文件夹中,例如。 /home/mike/BarcodeLibrary/external/BarcodeLibrary

然后引用将是:

android.library.reference.1=external/BarodeLibrary/

由您决定,将其放在相邻的文件夹中可以方便地重复使用和单独维护。将它放在项目本身中可以简化版本控制和持续集成。

更新AndroidManifest

您现在需要更新您的 AndroidManifest.xml

权限

将这些权限添加到 <manifest>如果它们尚未包括在内:

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FLASHLIGHT" />

特点

将这些功能添加到 <manifest>如果它们尚未包括在内:

<uses-feature android:name="android.hardware.camera" android:required="false"/>
<uses-feature android:name="android.hardware.camera.front" android:required="false"/>
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>
<uses-feature android:name="android.hardware.camera.flash" android:required="false"/>

条码 Activity 节点

<application> 中添加此 Activity 节点在底部。

<activity android:name="com.google.zxing.client.android.CaptureActivity"
android:screenOrientation="landscape"
android:configChanges="orientation|keyboardHidden"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden"
android:exported="false">
<intent-filter>
<action android:name="com.phonegap.plugins.barcodescanner.SCAN"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>

配置.xml

项目的res/config.xml 需要指定条形码插件。只需将以下行添加到 plugins 节点。

<plugin name="BarcodeScanner" value="com.phonegap.plugins.barcodescanner.BarcodeScanner"></plugin>

完成...

您应该能够继续构建项目:

ant debug

或者

cordova/run

关于android - 用于 phonegap android 的 Zxing 条码扫描器插件不适用于只有前置摄像头的 nexus 7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16919823/

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