Opening PDF in local storage with File Viewer Plugin

Opening PDF in local storage with File Viewer Plugin

  

Hello,

In my mobile app I create a PDF with jsPDF, and it's saved locally with the help of the FilePlugin.
This all works fine. I can browse to the location of the internal storage, and open the generated PDF.


My issue is now that I can't open this PDF via the FileViewerPlugin.
If I use an external PDF via an URL, it works fine.

I'm using the URI provided by the SaveFile action of the FilePlugin, and I don't  get an ErrorMessage or an ErrorCode from the FileViewerPlugin, but the 'Success' flag is still false.

If I replace the "file:///" portion of the URI with "content:///" the PDF Viewer opens ('Success' Flag is true), but the PDF is still not showing up.


Below is an example of the URI I'm using:
"file:///storage/emulated/0/Android/data/com.outsystemscloud.marcoressler.pdftestapp/files/pdfs/testPDF.pdf"

Edit: the MIME Type is of course set to "application/pdf"


What am I missing?

Many thanks!

Anyone got an idea? Or is it best to move this to the Forge Discussions?

Solution

It's the new security from Android Nougat now reject file:/// uri.

The native code in cordova github must be updated to use the new FileProvider approach.

https://developer.android.com/about/versions/nougat/android-7.0-changes

Sharing Files Between Apps

For apps targeting Android 7.0, the Android framework enforces the StrictMode API policy that prohibits exposing file:// URIs outside your app. If an intent containing a file URI leaves your app, the app fails with a FileUriExposedException exception.

To share files between applications, you should send a content:// URI and grant a temporary access permission on the URI. The easiest way to grant this permission is by using the FileProvider class. For more information on permissions and sharing files, see Sharing Files.


It's fixed in the original cordova plugin: https://github.com/sitewaerts/cordova-plugin-document-viewer


But it's not compatible with Outsystems (I tried), so we all have to wait for this plugin developer to implement it.

Solution

Ah, I see - thanks for the Info.

So we just have to wait and see until they update the plugin...

Problem is, this is not a supported plugin.

There's no confirmed date or will this ever be fixed.

Great news, it's been fixed. 


Check in Forge, go to File Viewer plugin, then check Version tab. 

Get version 1.2.0 (beta), it's working perfectly now.

Just pass file uri from File Plugin's SaveFile action.

You need to generate native APK again.


Thank you File Viewer Team for your time and effort.