Francisco Souza
Francisco Souza

Reputation: 828

Error scanning barcode with Ionic/cordova

I have an Ionic project and I installed this plugin to scan qrcodes:

cordova plugin add https://github.com/wildabeast/BarcodeScanner.git

But when I run the app on a samsung s5 device with Android 6.0 I get a camera error: "Sorry, the Android camera encountered a problem. You may need to restart the device" enter image description here

Any ideas of what causes this issue?

I have tested with:

ionic run android -l -c
ionic run android

This is my code executed when I press a button:

$scope.scanBarcode = function() {
  $ionicPlatform.ready(function() {
    $cordovaBarcodeScanner.scan().then(function(imageData) {
      console.log("Barcode text -> " + imageData.text);
      console.log("Barcode Format -> " + imageData.format);
      console.log("Cancelled -> " + imageData.cancelled); // prints: cancelled
    }, function(error) {
      console.log("An error happened -> " + error);
    });
  });
};

Upvotes: 0

Views: 982

Answers (2)

Suresh Kamrushi
Suresh Kamrushi

Reputation: 16086

For this issue you can try either of below solutions:

  1. It is permission issue with android 6. So to fix the issue configure platform to android 5.0.

OR if you are using MI note 4 you can try below additional steps:

There is another permission required in MIUI secruity system and after enabling it, camera started working.
Following are the steps you can follow to update the setting:

  1. Go to Security.
  2. Click on “Permissions” and again select “Permissions”
  3. Now from the list, click on “Camera”.
  4. It will list all the apps installed. Look for your app and enable the permission.

Upvotes: 2

Francisco Souza
Francisco Souza

Reputation: 828

This is what solved my problema, in the config.xml file in the "android" platform section I put:

<platform name="android">
     <preference name="android-targetSdkVersion" value="22"/>
</platform>

Upvotes: 1

Related Questions