科尔多瓦酒吧codescanner - 使用前置摄像头 [英] Cordova Barcodescanner - Use front facing camera

查看:328
本文介绍了科尔多瓦酒吧codescanner - 使用前置摄像头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用这条codescanner( https://github.com/wildabeast/酒吧$上的应用程序C $ cScanner )使用国产科尔多瓦,专门针对使用Android设备上。

I am using this barcodescanner (https://github.com/wildabeast/BarcodeScanner) on an app made using Cordova, specifically aimed at using on an Android device.

我有以下功能在JavaScript中设置了:

I have the following function set up in JavaScript:

$(document).ready(function(){    
    $('#scanner').click( function(){

        console.log('clicked'); //to see if the function is firing      
        cordova.plugins.barcodeScanner.scan(

        function (result) {
          alert("We got a barcode\n" +
                "Result: " + result.text + "\n" +
                "Format: " + result.format + "\n" +
                "Cancelled: " + result.cancelled);
        }, 
        function (error) {
          alert("Scanning failed: " + error);
        }
    );
    });    
});

作为提供这个插件的文件中提及。我已经使用CLI科尔多瓦它添加到我的项目:

as mentioned in the documentation provided for this plugin. I have added it into my project using the cordova CLI:

$ cordova add plugin https://github.com/wildabeast/BarcodeScanner.git

当我列出可用的插件,为我的项目,我可以看到它被正确安装。另外,我可以在我的应用程序使用相机的按钮发射了正确的功能,可以扫描使用后置摄像头,没有问题。

When I list the available plugins for my projects I can see that it is installed correctly. Also I can use the camera in my app with the button firing off the correct function and can scan using the back camera with no issues.

有没有使用前置摄像头进行扫描的方法吗?如果不是在插件中,有没有设置设备所使用的默认摄像头,在code,使用默认前置摄像头前面的方法吗?我们正在开发的需要该应用程序专门只使用前置摄像头,不需要背置摄像头。

Is there any way of using the front camera for the scan? If it is not in the plugin, is there any way of setting the default camera used by the device, in the code, to use the front facing camera by default? The app that we are developing needs to specifically use the front facing camera only and does not need the back facing camera.

任何帮助将AP preciated。

Any help will be appreciated.

推荐答案

下面是所有我们走上得到这个权利的步骤进行细分。很多来自不同源的输入归因于这个工作,但大多没有考虑到我们是不是Java开发人员,而且甚至有些最小的JAVA的做法是新的或未知的,甚至我们。该解决方案是从Web开发人员的角度。

Here is a breakdown of all the steps we took to get this right. A lot of input from different sources attributed to this working, but most of them not taking into consideration that we aren’t JAVA developers and that even some of the smallest JAVA practices are new or even unknown to us. This solution is from a web developer’s perspective.

工作存储库可以在这里找到适合使用: https://github.com/wilcovandeijl/camera_app

The working repository can be found here for use: https://github.com/wilcovandeijl/camera_app

感谢您@Leo的帮助。您的文章已经使我们在正确的方向,但这里是我们采取了最终的工作更详细的方法。如果你关心更详细地说明一点上您的文章我将AP preciate它,如果它是一个比最终制定不同的解决方案。

Thank you @Leo for your help. Your post had led us in the right direction, but here is a more detailed approach that we took that worked eventually. If you care to elaborate a little more on your post I would appreciate it, if it is a different solution than the one that eventually worked.

首先,我们增加了酒吧code扫描插件安装到我们的项目中使用CMD命令行:

Firstly we added the barcode scanner plugin into our project using CMD command line:

科尔多瓦插件添加com.phonegap.plugins.bar codescanner

更改目录随附默认的下载插件LibraryProject文件:

Change Directory to the LibraryProject file that comes default with the downloaded plugin:

CD<项目目录> \\插件\\ com.phonegap.plugins.bar codescanner的\\ src \\机器人\\ LibraryProject

与路径添加新的文件在此目录中称为local.properties您的SDK即

Add a new file in this directory called local.properties with the path to your SDK ie

sdk.dir = C:\\\\ \\\\用户\\\\ QQQ文件\\\\ \\\\的Andr​​oid ADT-束窗口-x86_64的\\\\ SDK

打开文件

<项目directory>plugins\\com.phonegap.plugins.bar$c$cscanner\\src\\android\\LibraryProject\\src\\com\\google\\zxing\\client\\android\\camera\\open\\GingerbreadOpenCameraInterface.java

编辑行48阅读:如果(cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT)

在CMD目录更改为:

CD<项目目录> \\插件\\ com.phonegap.plugins.bar codescanner的\\ src \\机器人\\ LibraryProject

在CMD键入蚂蚁发布。这将创建可在&LT找到一个classes.jar文件;项目目录> \\插件\\ com.phonegap.plugins.bar codescanner的\\ src \\机器人\\ LibraryProject \\ BIN

In CMD type ant release. This creates a classes.jar file that can be found in <project directory > \plugins\com.phonegap.plugins.barcodescanner\src\android\LibraryProject\bin.

如果你有一个无法解析目标的android-17错误,看一看的这个解决方案

If you got a Unable to resolve target 'android-17' error, take a look at this solution.

一个文件夹时,删除 com.google.zxing.client.android.captureactivity.jar 文件,但记得要复制的文件的名称。放下你的classes.jar文件到这个目录(\\插件\\ com.phonegap.plugins.bar codescanner的\\ src \\机器人\\ LibraryProject),并将其重命名为 com.google.zxing.client.android .captureactivity.jar

One folder up, delete the com.google.zxing.client.android.captureactivity.jar file, but remember to copy the name of the file. Drop your classes.jar file into this directory ( \plugins\com.phonegap.plugins.barcodescanner\src\android\LibraryProject ) and rename it to com.google.zxing.client.android.captureactivity.jar

最后还要复制新创建 com.google.zxing.client.android.captureactivity.jar 文件到&LT;项目目录&GT; \\平台\\机器人\\库目录

Finally also copy the newly created com.google.zxing.client.android.captureactivity.jar file to the <project directory>\platforms\android\libs directory.

您现在已经准备好运行命令科尔多瓦构建Android CMD中编译您的APK和你的设备上运行。

You are now ready to run the command cordova build android in CMD to compile your APK and run on your device.

感谢您@Leo对于这一点,我们的AP preciate你的帮助了很多。

Thank you to @Leo for your help with this we appreciate it a lot.

这篇关于科尔多瓦酒吧codescanner - 使用前置摄像头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆