thadeuszlay
thadeuszlay

Reputation: 3015

Set app permissions on Android 6.x (Marschmallow) in phonegap/cordova app

Beginning with Android 6.x (Marshmallow), the app should doesn't ask for permission before installing but while running.

I'm developing an app with phonegap that uses a barcode plugin in. When I run this app on Android 6.x it neither asks the user for permission before installing nor during run time. Instead it just shows you a box that the app is not working and the device has to be restarted.

According to http://phonegap.com/blog/2016/02/09/phonegap_6_now_on_build/ I added the following line into my config.xml file of my project (path: myProject/config.xml):

<preference name="phonegap-version" value="cli-6.0.0" />

I deployed locally, but it would still show the same error. Is there a way how to fix it? I'd prefer the app is showing this box before starting the installation.

UPDATE: In my manifest.xml I set it to his:

<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="23" />

I now have reduced the targetSdkVersion from 23 to 22. And the error doesn't show up. But it also doesn't ask for permission. How can I let it ask for permission?

Upvotes: 4

Views: 4604

Answers (1)

1nteger
1nteger

Reputation: 838

On Android 6 you need to request permission to use the camera at runtime when targeting API level 23+. Even if the uses-permission tag for the Camera is present in AndroidManifest.xml

Try link given below for Checking permission..

barcode-link

Example usage:

function hasCameraPermission() {
    cordova.plugins.barcodeScanner.hasCameraPermission(
      function(result) {
        // if this is 'false' you probably want to call 'requestCameraPermission' now
        alert(result);
      }
    )
  }

  function requestCameraPermission() {
    // no callbacks required as this opens a popup which returns async
    cordova.plugins.barcodeScanner.requestCameraPermission();
  }

good luck..

Upvotes: 4

Related Questions