cordova掃描二維碼

安裝cordova掃碼插件

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

然后在要頁面上添加調(diào)用的按鈕

<div ng-controller="erweimaCtrl">
    <button ng-click="erweima()">掃描二維碼</button>
</div>

然后在控制器里面寫調(diào)用的方法

angular.module('app').controller('erweimaCtrl', erweimaCtrl);
    erweimaCtrl.$inject = ['$scope'];
    function erweimaCtrl($scope) {
        //二維碼
        $scope.erweima = ()=> {
            cordova.plugins.barcodeScanner.scan(
                function(result) {
                    //掃碼成功后執(zhí)行的回調(diào)函數(shù)
                    alert("收到一個二維碼\n" +
                        "掃碼文字結(jié)果: " + result.text + "\n" +
                        "格式: " + result.format + "\n" +
                        "是否在掃碼頁面取消掃碼: " + result.cancelled);
                },
                function(error) {
                    //掃碼失敗執(zhí)行的回調(diào)函數(shù)
                    alert("Scanning failed: " + error);
                }, {
                    preferFrontCamera: true, // iOS and Android 設(shè)置前置攝像頭
                    showFlipCameraButton: true, // iOS and Android 顯示旋轉(zhuǎn)攝像頭按鈕
                    showTorchButton: true, // iOS and Android 顯示打開閃光燈按鈕
                    torchOn: false, // Android, launch with the torch switched on (if available)打開手電筒
                    prompt: "在掃描區(qū)域內(nèi)放置二維碼", // Android提示語
                    resultDisplayDuration: 500, // Android, display scanned text for X ms. 
                                            //0 suppresses it entirely, default 1500 設(shè)置掃碼時間的參數(shù)
                    formats: "QR_CODE", // 二維碼格式可設(shè)置多種類型
                    orientation: "portrait", // Android only (portrait|landscape), 
                                             //default unset so it rotates with the device在安卓上 landscape 是橫屏狀態(tài)   
                    disableAnimations: true, // iOS     是否禁止動畫
                    disableSuccessBeep: false // iOS      禁止成功后提示聲音 “滴”
                }
            );
        }
    }

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 179,058評論 25 709
  • 發(fā)現(xiàn) 關(guān)注 消息 iOS 第三方庫、插件、知名博客總結(jié) 作者大灰狼的小綿羊哥哥關(guān)注 2017.06.26 09:4...
    肇東周閱讀 15,360評論 4 61
  • 導(dǎo)語 這篇文章主要介紹了如何在Android平臺上使用Cordova 的command-line interfac...
    jorstinchan閱讀 22,835評論 6 41
  • Access學(xué)習(xí)了幾天,遇到了一點卡住了,在書上找不到答案,那天剛好有技術(shù)人員在,本想叫他教一方法,人家聽了我的要...
    宋寧靜閱讀 167評論 0 0
  • 摘錄:黃色對于目標(biāo)的執(zhí)著讓他們認(rèn)定逆境是一位偉大的教師,他們篤信那些一生都走平坦大道的人是培養(yǎng)不出力量的。黃色通過...
    壹顆大橙子閱讀 312評論 0 2

友情鏈接更多精彩內(nèi)容