cordova-plugin-filepath icon indicating copy to clipboard operation
cordova-plugin-filepath copied to clipboard

[Android] content:// to file://storage does not get resolve

Open indraraj26 opened this issue 4 years ago • 3 comments

Bug Report

Problem

When you take pdf anyother file from download you get URI with content://. So in order to resolve i use this package to get file URI path https://www.npmjs.com/package/cordova-plugin-filepath

What is expected to happen?

It should resolve and return file detail

What does actually happen?

It returns error code: 1 // not found

Information

chrome://inspect image

Command or Code

const options: CameraOptions = {
          quality: 50,
          destinationType: this._camera.DestinationType.FILE_URI,
          mediaType: this._camera.MediaType.ALLMEDIA,
          sourceType: this._camera.PictureSourceType.SAVEDPHOTOALBUM,
          saveToPhotoAlbum: false,
        };
 if (file.indexOf("content://") > -1) {
          console.log("content //", file);
          window.FilePath.resolveNativePath(file, (success) => {
            console.log(success, "content");
            window.resolveLocalFileSystemURL(success, (fileEntry) => {
              console.log(fileEntry, "fileEntry");
              fileEntry.file((finalFile) => {
                console.log(finalFile, "resolve");
                resolve(finalFile);
              });
            });
          });
        }

Environment, Platform, Device

All Android version i think so btw currently i am testing on Android 10

Version information

Cordova CLI : 10.0.0 Cordova Platforms : android 9.0.0

Checklist

  • [X] I searched for existing GitHub issues
  • [X] I updated all Cordova tooling to most recent version
  • [X] I included all the necessary information above

indraraj26 avatar Dec 09 '20 08:12 indraraj26

In your Android Manifest, add this android:requestLegacyExternalStorage="true" in the application tag.

Houdhey avatar Feb 08 '21 13:02 Houdhey

Hi, It is already in place Repo to reproduce: https://github.com/indraraj26/cordova-camera-fast-click/tree/content-file-path Branch: content-file-path On Android 10 it returns code 1 error i.e file not found

Android 7 vs Android 10 image

Issue Thread on cordova plugin file: https://github.com/apache/cordova-plugin-file/issues/443

indraraj26 avatar Feb 08 '21 14:02 indraraj26

Here is what I did to solve my Android 10 problems, similar to yours:

  • Android manifest: add the request Legacy External Storage true
  • Before opening a file, I had to ask for permission, and I used Ionic Diagnostic plugin for this: this.diagnostic.requestExternalStorageAuthorization().then((permission) => console.log('permission storage asked' + permission));

Houdhey avatar Feb 08 '21 14:02 Houdhey