科尔多瓦 - 插件摄像头:拒绝权限:读com.android.providers.media.MediaDocumentsProvider需要android.permission.MANAGE_DOCUMENTS [英] cordova-plugin-camera: Permission Denial: reading com.android.providers.media.MediaDocumentsProvider requires android.permission.MANAGE_DOCUMENTS

查看:5367
本文介绍了科尔多瓦 - 插件摄像头:拒绝权限:读com.android.providers.media.MediaDocumentsProvider需要android.permission.MANAGE_DOCUMENTS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个离子的移动应用程序,并在我的应用程序,我希望能够从图库中选择图片,但我选择图像后,得到这个错误

I have an ionic mobile app and in my app, I want to be able to select images from gallery but I get this error after selecting the image

java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaDocumentsProvider uri content://com.android.providers.media.documents/document/image:58 from pid=2173, uid=10062 requires android.permission.MANAGE_DOCUMENTS, or grantUriPermission()

这是我的code,从库中选择图像,并将其添加

this is my code to select image from gallery and add it

var options = {
      destinationType : Camera.DestinationType.FILE_URI,
      sourceType : Camera.PictureSourceType.PHOTOLIBRARY,
      allowEdit : false,
      encodingType: Camera.EncodingType.JPEG,
      popoverOptions: CameraPopoverOptions,
      mediaType: Camera.MediaType.PICTURE,
      correctOrientation: true
    };

   // 3
    $cordovaCamera.getPicture(options).then(function(imageData) {
   // 4
      var imagetype;
      onImageSuccess(imageData);
      function onImageSuccess(fileURI) {
        console.log("im in image success")
        console.log(fileURI)
        createFileEntry(fileURI);
      }

      function createFileEntry(fileURI) {
        console.log("im in create file entry")
        console.log(fileURI)
        window.resolveLocalFileSystemURL(fileURI, copyFile, fail);
      }

       // 5
      function copyFile(fileEntry) {
        console.log("im in file entry")
        console.log(fileEntry)
        var name = fileEntry.fullPath.substr(fileEntry.fullPath.lastIndexOf('/') + 1);
        var newName = (new Date()).getTime() + name;
         halfthru(fileEntry, newName); //diff
         getImageType(fileEntry); //diff

      }

      function getImageType(fileEntry) { //diff
        var typeImage;
        $scope.$evalAsync(function() {
          fileEntry.file(function(file){
            console.log(fileEntry.file)
            console.log(file)
            typeImage= file.type;
            $scope.imagelist = typeImage;
            imagetype = typeImage;
          }, function(e){
          });
        })

      }

     function halfthru(fileEntry, newName) {
      console.log("halftru")
        window.resolveLocalFileSystemURL(cordova.file.dataDirectory, function(fileSystem2) {
          fileEntry.copyTo(
            fileSystem2,
            newName,
            onCopySuccess,
            fail
          );
        }, fail);
      }

      // 6
      function onCopySuccess(entry) {
        console.log("im in copy success")
        console.log(entry)
          $scope.activeSlide = index;
          if(modalExists === false) {
            $ionicModal.fromTemplateUrl('image-modal.html', {
              scope: $scope,
            }).then(function(modal) {

              $scope.modal1 = modal;
              $scope.modal1.show();
              modalExists = true;
              $scope.$evalAsync($scope.images.push({file: entry.nativeURL, type: $scope.imagelist}));
              imagesModalCount =  $scope.images.length;
              attachedImageCount = $scope.imagesAttached.length;
            });
          }
          else {
            $scope.modal1.show();
            $scope.$evalAsync($scope.images.push({file: entry.nativeURL, type: $scope.imagelist}));
            imagesModalCount =  $scope.images.length;
            attachedImageCount  = $scope.imagesAttached.length;
          }

          $scope.$on('$destroy', function() {
            $scope.modal1.remove();
          });

      }

      function fail(error) {

      }
    }, function(err) {

    });

我的config.xml文件

my config.xml file

<platform name="android">
    <icon src="resources/android/icon/drawable-ldpi-icon.png" density="ldpi"/>
    <icon src="resources/android/icon/drawable-mdpi-icon.png" density="mdpi"/>
    <icon src="resources/android/icon/drawable-hdpi-icon.png" density="hdpi"/>
    <icon src="resources/android/icon/drawable-xhdpi-icon.png" density="xhdpi"/>
    <icon src="resources/android/icon/drawable-xxhdpi-icon.png" density="xxhdpi"/>
    <icon src="resources/android/icon/drawable-xxxhdpi-icon.png" density="xxxhdpi"/>
    <splash src="resources/android/splash/drawable-land-ldpi-screen.png" density="land-ldpi"/>
    <splash src="resources/android/splash/drawable-land-mdpi-screen.png" density="land-mdpi"/>
    <splash src="resources/android/splash/drawable-land-hdpi-screen.png" density="land-hdpi"/>
    <splash src="resources/android/splash/drawable-land-xhdpi-screen.png" density="land-xhdpi"/>
    <splash src="resources/android/splash/drawable-port-ldpi-screen.png" density="port-ldpi"/>
    <splash src="resources/android/splash/drawable-port-mdpi-screen.png" density="port-mdpi"/>
    <splash src="resources/android/splash/drawable-port-hdpi-screen.png" density="port-hdpi"/>
    <splash src="resources/android/splash/drawable-port-xhdpi-screen.png" density="port-xhdpi"/>
    <splash src="resources/android/splash/drawable-port-xxhdpi-screen.png" density="port-xxhdpi"/>
    <splash src="resources/android/splash/drawable-port-xxxhdpi-screen.png" density="port-xxxhdpi"/>
    <config-file target="AndroidManifest.xml" parent="/*">
      <uses-permission platform="android" name="android.permission.MANAGE_DOCUMENTS" />
        </config-file>
  </platform>

这是一款Android 5.1.1的手机上发生的事情。

This is happening on an android 5.1.1 phone.

我的猜测将在以某种方式从科尔多瓦文件-插件时引起resolveLocalFileSystemURL方法被调用但我怎么解决这个问题?

My guess will be this is caused somehow from the cordova-file-plugin when resolveLocalFileSystemURL method is called but how do i solve this?

推荐答案

它说,你需要MANAGE_DOCUMENTS权限,你在你的config.xml中添加此权限吗?

It says that you need MANAGE_DOCUMENTS permissions, have you add this permission in your config.xml ?

&LT;使用许可权的android:NAME =android.permission.MANAGE_DOCUMENTS/&GT;

在我的应用程序,从图库添加图像我做的:

In my app, to add an image from gallery I do:

$scope.addMedia = function addMedia() {
    var buttons = [];
    var onCameraSuccess = function onCameraSuccess(imageData) {
        $scope.files.push(imageData);
    };

    var onCameraError = function onCameraError() {};

    var photoConfig = {
        quality: 70,
        targetWidth: 400,
        targetHeight: 400,
        allowEdit: false,
        destinationType: window.navigator.camera.DestinationType.DATA_URL,
        encodingType: window.navigator.camera.EncodingType.JPEG,
        saveToPhotoAlbum: false,
        mediaType: window.navigator.camera.MediaType.ALLMEDIA,
        cameraDirection: window.navigator.camera.Direction.BACK
    };

    buttons.push({
        text: 'Take a photo',
        action: function cameraUpload() {
            // Camera upload
            window.navigator.camera.getPicture(onCameraSuccess, onCameraError, angular.extend({
                sourceType: window.navigator.camera.PictureSourceType.CAMERA
            }, photoConfig));
        }
    });

    buttons.push({
        text: 'Choose a photo',
        action: function deviceUpload() {
            // Device upload
            window.navigator.camera.getPicture(onCameraSuccess, onCameraError, angular.extend({
                sourceType: window.navigator.camera.PictureSourceType.PHOTOLIBRARY
            }, photoConfig));
        }
    });

    $ionicActionSheet.show({
        buttons: buttons,
        cancelText: 'Cancel',
        cancel: function cancel() {},
        buttonClicked: function buttonClicked(index) {
            buttons[index].action();

            return true;
        }
    });
};

这篇关于科尔多瓦 - 插件摄像头:拒绝权限:读com.android.providers.media.MediaDocumentsProvider需要android.permission.MANAGE_DOCUMENTS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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