用于phonegap android的Zxing条码扫描器插件不能在只有前置摄像头的nexus 7上工作

时间:2013-06-04 13:58:35

标签: android cordova

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

1 个答案:

答案 0 :(得分:10)

要使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 库项目作为可用活动,检查AndroidManifest.xml, ant.properties, assets, bin...内是否有/home/mike/BarcodeLibrary等。

我用Nexus 7检查了这个,插件中包含的zxing库代码工作正常。 (这是zxing 2.1而不是2.2)

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

更新库以使用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"/>

条形码活动节点

在底部的<application>内添加此活动节点。

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

的Config.xml

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

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

完成...

您应该可以继续构建项目:

ant debug

或者

cordova/run