Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not allowed to load local resource: ionic 3 android

I am using ionic 3 android build apk and trying to laod image from file:///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, currentName, this.createFileName());
            }
          }, (err) => {
            this.presentToast('Error while selecting image.');
          });


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


      }

Error: Not allowed to load local resource
android 6.0.1

like image 851
Muneeb Khan Avatar asked Aug 28 '18 10:08

Muneeb Khan


2 Answers

No Need To Downgrade just write this code.

private win: any = window;
    this.win.Ionic.WebView.convertFileSrc(path);
like image 181
kunal shaktawat Avatar answered Nov 07 '22 14:11

kunal shaktawat


I had the same issues and it turns out that The new ionic webview plugin is the cause for the problem.

The new plugin: cordova-plugin-ionic-webview @ 2.x seem unstable...

to get it working downgraded back to [email protected] and all should work

Steps:

1. uninstall webview

ionic cordova plugins rm cordova-plugin-ionic-webview

2. install old one:

ionic cordova plugins add [email protected]

3. clean cordova

cordova clean android
like image 17
Awesome Jim Avatar answered Nov 07 '22 16:11

Awesome Jim