不允许加载本地资源:ionic 3 android

前端之家收集整理的这篇文章主要介绍了不允许加载本地资源:ionic 3 android前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用ionic 3 android build apk并尝试从文件添加图像:///storage/emulated/0/data/io.ionic.vdeovalet/cache/image.jpeg



    takePicture(sourceType) {
        try {
    // Create options for the Camera Dialog
          var options = {
            quality: 100,destinationType: this.camera.DestinationType.FILE_URI,encodingType: this.camera.EncodingType.JPEG,sourceType: sourceType,};
          this.camera.getPicture(options).then((imagePath) => {
    // Special handling for Android library
            if (this.platform.is('android') && sourceType ===
              this.camera.PictureSourceType.PHOTOLIBRARY) {
              this.filePath.resolveNativePath(imagePath)
                .then(filePath => {
                  let correctPath = filePath.substr(0,filePath.lastIndexOf('/') + 1);
                  let currentName = imagePath.substring(imagePath.lastIndexOf('/') + 1,imagePath.lastIndexOf('?'));
                  this.copyFileToLocalDir(correctPath,currentName,this.createFileName());
                  this.lastImage = filePath;
                });
            } else {
              var currentName = imagePath.substr(imagePath.lastIndexOf('/') + 1);
              var correctPath = imagePath.substr(0,imagePath.lastIndexOf('/') + 1);
              this.copyFileToLocalDir(correctPath,this.createFileName());
            }
          },(err) => {
            this.presentToast('Error while selecting image.');
          });


        } catch (e) {
          console.error(e);
        }


      }

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

解决方法

我遇到了同样的问题,结果证明了这一点
新的离子webview插件是导致问题的原因.

插件:cordova-plugin-ionic-webview @ 2.x似乎不稳定……

让它降级回到cordova-plugin-ionic-webview@1.2.1并且一切都应该工作

脚步:

1.卸载webview

ionic cordova plugins rm cordova-plugin-ionic-webview

2.安装旧的:

ionic cordova plugins add cordova-plugin-ionic-webview@1.2.1

3.清洁cordova

cordova clean android

猜你在找的Android相关文章