Cordova App 'Android permission Cordova plugin' is not showing permission dialog

12,276

Solution 1

I was able to get the permissions request to show by adding the relevant permissions and feature to platforms/android/AndroidManifest.xml.

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-feature android:name="android.hardware.camera" android:required="true" />

Solution 2

In config.xml file, try to add

enter image description here

and then build the app. It will automatically override AndroidManifest.xml file in platforms folder and thus the popup dialog with deny and allow button works fine.

Kindly see the below link for more reference.

https://inthecheesefactory.com/blog/things-you-need-to-know-about-android-m-permission-developer-edition/en

Solution 3

I had a same issue dear . the requesting dialog box did not appear. after some concentration on my code, i found that, var permissions = cordova.plugins.permissions is defined in DeviceReady() function and in the other side i was calling checkPermissionCallback() as a callback function which is not in DeviceReady() function so var permissions is not defined in that function (scopes are different). so checkPermissionCallback have must been defined in DeviceReady() function.

Share:
12,276

Related videos on Youtube

Mahmoud Mabrouk
Author by

Mahmoud Mabrouk

I am a front-end developer, Javascript is the most beautiful programming language I've ever worked on, Actually, I worked on most of Javascript's frameworks and technologies.

Updated on September 15, 2022

Comments

  • Mahmoud Mabrouk
    Mahmoud Mabrouk over 1 year

    i am attending to use 'imagepicker' plugin for my cordova app to get images from the mobile gallery and use them . i am testing my app on android 6.0 device and this is the problem, marshmallow Android 6.0 require in run-time permission not like the older versions "it is working on older versions" ,but on api 23 or higher when it attend to open gallery it close immediately and the app crashes . when i searched i found that i need permission to do it . so i started to use "Android permission Cordova plugin" and by copying the example they presented in this page : https://www.npmjs.com/package/cordova-plugin-android-permissions

    which is :

    var permissions = cordova.plugins.permissions;
    permissions.hasPermission(permissions.CAMERA, checkPermissionCallback, null);
    
    function checkPermissionCallback(status) {
      if(!status.hasPermission) {
        var errorCallback = function() {
          console.warn('Camera permission is not turned on');
        }
    
        permissions.requestPermission(
          permissions.CAMERA,
          function(status) {
            if(!status.hasPermission) errorCallback();
          },
          errorCallback);
      }
    }
    

    the console always says : 'Camera permission is not turned on' and no permission dialog shows.

    then i searched again and found this solved question and it`s answer , so i installed 'cordova-plugin-diagnostic' and tried this code:

    function requestPermission(){
        cordova.plugins.diagnostic.requestRuntimePermission(function(status){
            switch(status){
                case cordova.plugins.diagnostic.runtimePermissionStatus.GRANTED:
                    console.log("Permission granted (or already granted) - call the plugin");
                    // call SQLite plugin
                    break;
                case cordova.plugins.diagnostic.runtimePermissionStatus.DENIED:
                    console.log("Permission denied - ask again");
                    alert("Come on user, we really need this. I'll ask again...");
                    requestPermission();
                    break;
                case cordova.plugins.diagnostic.runtimePermissionStatus.DENIED_ALWAYS:
                    console.log("Permission permanently denied");
                    alert("Well that's it, we're dead Jim");
                    navigator.app.exitApp();
                    break;
            }
        }, function(error){
            console.error("The following error occurred: "+error);
        }, cordova.plugins.diagnostic.runtimePermission.READ_PHONE_STATE);
    }
    requestPermission();
    

    the app close and no dialog shows too, i think i can`t get what should this plugins do and how can i get the permission to open gallery. if can somebody give me full example to open gallery and pick image with permission it will be great help.

    sorry for my English , and thanks for being patient .