Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pdf preview closed immediately on android #11

Closed
jordan-jarolim opened this issue Jan 6, 2021 · 3 comments
Closed

Pdf preview closed immediately on android #11

jordan-jarolim opened this issue Jan 6, 2021 · 3 comments

Comments

@jordan-jarolim
Copy link

Hi, I am trying to use the library to preview a file stored locally on the device (file is saved by Capacitor.Plugins.Filesystem). Everything works just ok on iOS, file preview is displayed as expected but I have troubles on android. File preview is closed immediately. File path is 'file:https:///storage/emulated/0/Documents/Payslip.pdf'. I also tried different locations.

I played a bit with the Java code and ended up having a solution which is proposed here: https://inthecheesefactory.com/blog/how-to-share-access-to-file-with-fileprovider-on-android-nougat/en. This is working for me, however, this is the exact opposite from what is mentioned in the readme about file:https:// vs content:https:// uri.

Specifically, I added this part in presentFile method:

private void presentFile(Intent intent, Uri uri, String type) {
    File myFile = new File(String.valueOf(uri).replace("file:https://", ""));
    Uri myUri = FileProvider.getUriForFile(this.context, this.context.getApplicationContext().getPackageName() + ".provider", myFile);
    intent.setDataAndType(myUri, type);
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    this.cordova.getActivity().startActivityForResult(intent, 1);
  }

Could you please point me to a right direction what I might be doing wrong? I am absolutely new to android programming. You can find my working solution here: ufirstgroup@f783da3

Thank you.

@jordan-jarolim
Copy link
Author

Now I am starting to understand your tiny hack there :) https://stackoverflow.com/questions/38200282/android-os-fileuriexposedexception-file-storage-emulated-0-test-txt-exposed - would it make sense to completely migrate to content:https:// schema? I am happy to do a pull request in case you agree. But I am not sure about the other consequences.

Thank you

@mostafa-mansour1
Copy link
Owner

if u can fix it, please do it and I will merge your changes

@mostafa-mansour1
Copy link
Owner

I fix this with android FileProvider, kindly get the new version, and it has new features for preview the files from anywhere

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

No branches or pull requests

2 participants