哪个用于phonegap android的条码扫描程序插件也适用于前置摄像头?
答案 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库代码,但这是不必要的,需要额外的工作/测试。
您需要更新/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/www
和src/com/phonegap/plugins/barcodescanner
。
现在您需要更新project.properties
以包含BarcodeLibrary
,编辑它以包含新行:
android.library.reference.1=../BarodeLibrary/
(如果您有更多要引用的库,则需要对它们进行编号,以允许对编译依赖性进行排序。)
注意,如果您想将库直接包含到主项目中,可以将其复制到文件夹中,例如。 /home/mike/BarcodeLibrary/external/BarcodeLibrary
参考将是:
android.library.reference.1=external/BarodeLibrary/
由您决定,将其保留在相邻文件夹中,可以轻松重复使用,并单独维护。将它放在项目本身可以简化版本控制和持续集成。
您现在需要更新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>
项目的 res / config.xml 需要指定条形码插件。只需将以下行添加到插件节点。
<plugin name="BarcodeScanner" value="com.phonegap.plugins.barcodescanner.BarcodeScanner"></plugin>
您应该可以继续构建项目:
ant debug
或者
cordova/run