Cordova,条码扫描程序在Android

时间:2015-09-01 16:32:09

标签: android cordova ionic-framework barcode-scanner angularjs-ng-click

使用模拟器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>

1 个答案:

答案 0 :(得分:4)

而不是数据 - tap-disabled =“true”失去了UI触摸效果,我通过使用触摸而不是ng-click来实现它。我不知道为什么。

{{1}}