簡體   English   中英

科爾多瓦插件相機無法捕獲圖像resolveLocalFileSystemURL android 5

[英]cordova plugin camera not capturing image resolveLocalFileSystemURL error on android 5

我正在嘗試使用Google Nexus 5在我的離子應用程序中從圖庫中添加圖像,但是我一直運行到相同的錯誤消息

W/System.err( 2544): java.lang.NullPointerException: Attempt to invoke virtual method 'long java.lang.Long.longValue()' on a null object reference
W/System.err( 2544):    at org.apache.cordova.file.ContentFilesystem.getFileMetadataForLocalURL(ContentFilesystem.java:130)
W/System.err( 2544):    at org.apache.cordova.file.Filesystem.exists(Filesystem.java:130)
W/System.err( 2544):    at org.apache.cordova.file.FileUtils.resolveLocalFileSystemURI(FileUtils.java:619)
W/System.err( 2544):    at org.apache.cordova.file.FileUtils.access$400(FileUtils.java:51)
W/System.err( 2544):    at org.apache.cordova.file.FileUtils$14.run(FileUtils.java:378)
W/System.err( 2544):    at org.apache.cordova.file.FileUtils$25.run(FileUtils.java:561)
W/System.err( 2544):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
W/System.err( 2544):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
W/System.err( 2544):    at java.lang.Thread.run(Thread.java:818)

我的angularjs代碼

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

      function createFileEntry(fileURI) {
        window.resolveLocalFileSystemURL(fileURI, copyFile, fail);
      }

       // 5
      function copyFile(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){
            typeImage= file.type;
            $scope.imagelist = typeImage;
            imagetype = typeImage;
          }, function(e){
          });
        })

      }

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

      // 6
      function onCopySuccess(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) {

    });

我知道這個問題與cordova插件文件和一些android 5問題有關,但是我該如何解決呢?

切換到NativeURL似乎可以解決問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM