Cordova应用"Android许可Cordova插件"未显示许可对话框 [英] Cordova App 'Android permission Cordova plugin' is not showing permission dialog

查看:133
本文介绍了Cordova应用"Android许可Cordova插件"未显示许可对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的cordova应用程序使用"imagepicker"插件来从移动图库中获取图像并使用它们.我正在android 6.0设备上测试我的应用,这就是问题所在,棉花糖Android 6.0需要在运行时权限,而不是较旧版本它正在较旧版本上工作",而是在api 23或更高版本上参加开放画廊它立即关闭并导致应用程序崩溃.当我搜寻时,我发现我需要得到许可才能这样做.因此,我开始使用"Android权限Cordova插件",并复制了他们在此页面中显示的示例:

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

是:

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.

然后我再次搜索,找到了已解决的问题及其答案,因此我安装了"cordova-plugin-diagnostic"并尝试了以下代码:

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 .

推荐答案

我能够通过将相关的权限和功能添加到platform/android/AndroidManifest.xml来获得显示的权限请求.

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" />

这篇关于Cordova应用"Android许可Cordova插件"未显示许可对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆