Search code examples
javascriptandroidcordovasapui5barcode-scanner

Camera is not opening to scan Barcode in SAP UI5


I am designing SAP UI5 application to scan a Barcode. Home Screen contains a Button, on click of it Camera should look for Barcode. But my Camera is not at all opening.Below is my controller code-

_Scanner : function(oEvent){
             alert("looking for camera");
             cordova.plugins.barcodeScanner.scan(

                      function (result) {

                          alert("We got a barcode" + result.text);

                      },

                      function (error) {

                          alert("Scanning failed: "+error);

                      }

                   );
             alert("will look for camera2");
                  }

index.html

<script type=”text/javascript” src=”cordova.js”></script>

<script type=”text/javascript” src=”js/index.js”></script>

I am adding barcode plugin using below command- cordova plugin add cordova-plugin-barcodescanner (it is adding successfully in cmd)

I am testing this application on Android v6. let me know the solution


Solution

  • I used device ready function. Now, it is working