科尔多瓦条码扫描器在Android中打开两次

使用模拟器CordovaSim或Ionic View应用程序不会出现此问题,只有在为Android构建项目时才出现.
出现问题时,条形码读取器需要读取DATA_MATRIX代码两次,以返回到应用程序.

$cordova -v
5.2.0   

$cordova platform ls
android 4.1.1

$cordova plugin ls
cordova-plugin-barcodescanner 0.7.0 "BarcodeScanner"

我的config.xml的一部分:

    <feature name="BarcodeScanner">
    <param name="android-package" value="com.phonegap.plugins.barcodescanner.BarcodeScanner" />
    <param name="wp-package" value="BarcodeScanner" />
    <param name="id" value="cordova-plugin-barcodescanner" />
</feature>

条形码读取器的控制器:

angular.module('starter.controllers', [])
.controller('ScanCtrl', function($scope, $http, $ionicPopup) {
$scope.message = '';
$scope.click = function() {
    console.log("apertura scanner");
    $scope.message = '';
    cordova.plugins.barcodeScanner.scan(
        function (result) {

            if(result.cancelled == false){
                if(result.format == "DATA_MATRIX"){
                    var jsonToSend = result.text;

                    validate(jsonToSend);
                } else {
                    console.log("formato codice a barre non riconosciuto");
                }
            }else{
                console.log("lettura annullata");
            }                       
        }, 
        function (error) {
            alert("Errore scansione: " + error);
        }
    );
}

$scope.clear = function() {
    $scope.message = '';
}

validate = function(textJSON){
    console.log(textJSON);
    $http.post('http://www.esempio.con', textJSON).
      then(function(response) {
         console.log("success");
         console.log(angular.toJson(response));
         $scope.data = response.data.response;
         //alert(response.data.response);

         if(response.data.response == true){
            showAlert(true);
             $scope.message = '<img src="img/success.png" alt="" /><p>non valida</p>';
         }else{
            showAlert(false);
             $scope.message = '<img src="img/error.png" alt="" /><p>non valida</p>';
         }

      }, function(response) {
          $scope.data = "errore " + response.status + " " +response.statusText;
          console.error(response.status);
          console.error(response.statusText);
      });
}

// An alert dialog
showAlert = function(response) {
    if(response == true){
        var alertPopup = $ionicPopup.alert({
              title: "Risultato",
              templateUrl: 'templates/popupTrue.html',
              scope: $scope,
              cssClass: 'resultPopup',
              okText: 'Chiudi'
          });
    } else {
        var alertPopup = $ionicPopup.alert({
              title: "Risultato",
              templateUrl: 'templates/popupFalse.html',
              scope: $scope,
              cssClass: 'resultPopup',
              okText: 'Chiudi'
          });
    } 
  alertPopup.then(function(res) {
    console.log('alert mostrato');
  });
}
})

视图的一部分:

<ion-slide ng-controller="ScanCtrl">
             <div class="contenuto">
                   <h2>Scansione</h2>
                    <div>
                        <button style="border-radius:7px; margin-left:auto; margin-right: auto;" class="button button-large icon-left ion-ios-barcode-outline" ng-click="click()">
                            Avvia Scansione
                        </button>
                    </div>
                    <div style="margin-top: 5px;" ng-bind-html="message"></div>

                    <div style="margin-top: 5px;" ng-show="message.length!=0">
                        <button style="border-radius: 7px;margin-left:auto; margin-right: auto;" class="button button-large icon-left ion-trash-b" ng-click="clear()">
                            Pulisci Risultato
                        </button>
                    </div>
                </div>
           </ion-slide>

解决方法:

我没有使用失去触摸效果的data-tap-disabled =“ true”,而是通过使用触摸而不是ng-click使其工作了.我不知道为什么.

<button on-touch="click()">
    Avvia Scansione
</button>
上一篇:java-与Applaud类似的Phonegap Eclipse插件


下一篇:angularjs-如何永久运行Ionic服务?