cordova扫描二维码

安装cordova扫码插件

cordova plugin add https://github.com/phonegap/phonegap-plugin-barcodescanner.git

然后在要页面上添加调用的按钮

<div ng-controller="erweimaCtrl">
    <button ng-click="erweima()">扫描二维码</button>
</div>

然后在控制器里面写调用的方法

angular.module('app').controller('erweimaCtrl', erweimaCtrl);
    erweimaCtrl.$inject = ['$scope'];
    function erweimaCtrl($scope) {
        //二维码
        $scope.erweima = ()=> {
            cordova.plugins.barcodeScanner.scan(
                function(result) {
                    //扫码成功后执行的回调函数
                    alert("收到一个二维码\n" +
                        "扫码文字结果: " + result.text + "\n" +
                        "格式: " + result.format + "\n" +
                        "是否在扫码页面取消扫码: " + result.cancelled);
                },
                function(error) {
                    //扫码失败执行的回调函数
                    alert("Scanning failed: " + error);
                }, {
                    preferFrontCamera: true, // iOS and Android 设置前置摄像头
                    showFlipCameraButton: true, // iOS and Android 显示旋转摄像头按钮
                    showTorchButton: true, // iOS and Android 显示打开闪光灯按钮
                    torchOn: false, // Android, launch with the torch switched on (if available)打开手电筒
                    prompt: "在扫描区域内放置二维码", // Android提示语
                    resultDisplayDuration: 500, // Android, display scanned text for X ms. 
                                            //0 suppresses it entirely, default 1500 设置扫码时间的参数
                    formats: "QR_CODE", // 二维码格式可设置多种类型
                    orientation: "portrait", // Android only (portrait|landscape), 
                                             //default unset so it rotates with the device在安卓上 landscape 是横屏状态   
                    disableAnimations: true, // iOS     是否禁止动画
                    disableSuccessBeep: false // iOS      禁止成功后提示声音 “滴”
                }
            );
        }
    }

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,638评论 25 708
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,259评论 4 61
  • 导语 这篇文章主要介绍了如何在Android平台上使用Cordova 的command-line interfac...
    jorstinchan阅读 22,731评论 6 41
  • Access学习了几天,遇到了一点卡住了,在书上找不到答案,那天刚好有技术人员在,本想叫他教一方法,人家听了我的要...
    宋宁静阅读 153评论 0 0
  • 摘录:黄色对于目标的执着让他们认定逆境是一位伟大的教师,他们笃信那些一生都走平坦大道的人是培养不出力量的。黄色通过...
    壹颗大橙子阅读 270评论 0 2