首页 > 解决方案 > 不允许加载本地资源:ionic 3 android

问题描述

我正在使用 ionic 3 android build apk 并尝试从file:///storage/emulated/0/data/io.ionic.vdeovalet/cache/image.jpeg 加载图像



    拍摄图片(来源类型){
        尝试 {
    // 为相机对话框创建选项
          变量选项 = {
            质量:100,
            目的地类型:this.camera.DestinationType.FILE_URI,
            encodingType:this.camera.EncodingType.JPEG,
            源类型:源类型,
          };
          this.camera.getPicture(options).then((imagePath) => {
    // Android 库的特殊处理
            if (this.platform.is('android') && sourceType ===
              this.camera.PictureSourceType.PHOTOLIBRARY) {
              this.filePath.resolveNativePath(imagePath)
                .then(filePath => {
                  let correctPath = filePath.substr(0, filePath.lastIndexOf('/') + 1);
                  让 currentName = imagePath.substring(imagePath.lastIndexOf('/') + 1,
                    imagePath.lastIndexOf('?'));
                  this.copyFileToLocalDir(correctPath, currentName, this.createFileName());
                  this.lastImage = 文件路径;
                });
            } 别的 {
              var currentName = imagePath.substr(imagePath.lastIndexOf('/') + 1);
              var correctPath = imagePath.substr(0, imagePath.lastIndexOf('/') + 1);
              this.copyFileToLocalDir(correctPath, currentName, this.createFileName());
            }
          },(错误)=> {
            this.presentToast('选择图片时出错');
          });


        } 抓住 (e) {
          控制台.错误(e);
        }


      }

错误:不允许加载本地资源
android 6.0.1

标签: androidfilepathionic3android-6.0-marshmallow

解决方案


无需降级只需编写此代码。

private win: any = window;
    this.win.Ionic.WebView.convertFileSrc(path);

推荐阅读