在 phonegap/cordova 应用中对 Android 6.x (Marschmallow) 设置应用权限

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

从 Android 6.x (Marshmallow) 开始,应用程序在安装前不应请求许可,但在 运行ning.

我正在开发一个带有 phonegap 的应用程序,它使用条形码插件。当我 运行 这个应用程序在 Android 6.x 上时,它既不在安装前询问用户许可,也不在 运行 时间内。相反,它只是向您显示一个框,表明该应用程序无法运行并且必须重新启动设备。

根据 http://phonegap.com/blog/2016/02/09/phonegap_6_now_on_build/,我在项目的 config.xml 文件中添加了以下行(路径:myProject/config.xml):

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

我在本地部署了,还是报同样的错误。有办法解决吗?我希望应用程序在开始安装之前显示此框。

更新:在我的manifest.xml中,我将其设置为他的:

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

我现在已将 targetSdkVersion 从 23 减少到 22。错误没有出现。但它也不征求许可。怎么让它请求权限?

在 Android 6 上,当目标 API 级别 23+ 时,您需要请求权限才能在运行时使用相机。即使 AndroidManifest.xml

中存在相机的使用权限标签

尝试下面给出的 link 检查权限..

barcode-link

用法示例:

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();
  }

祝你好运..