Skip to content
This repository has been archived by the owner on Nov 9, 2021. It is now read-only.

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

Open
3 tasks done
indraraj26 opened this issue Dec 9, 2020 · 3 comments
Open
3 tasks done

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

indraraj26 opened this issue Dec 9, 2020 · 3 comments

Comments

@indraraj26
Copy link

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

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above
@Houdhey
Copy link

Houdhey commented Feb 8, 2021

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

@indraraj26
Copy link
Author

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: apache/cordova-plugin-file#443

@Houdhey
Copy link

Houdhey commented Feb 8, 2021

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));

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants