0

My ionic app downloads a PDF file and then tries to open it using Cordova FileOpener2 plugin:

var targetPath = "file:///storage/emulated/0/Android/data/myapp/files/myDir/fds/30510L109.pdf";
$cordovaFileOpener2.open(targetPath, 'application/pdf')
                        .then(function() {
                                // file opened successfully
                            },
                            function(err) {
                                util.logObject(err, "Open error");
                            });

but I get this error:

An error occurred: "file:///storage/emulated/0/Android/data/caliatys.edata/files/E-data/certificates/9360432001-H44K95L-en.pdf exposed beyond app through Intent.getData()"

EDIT

After some research and debug, I've found that this exception is thrown: FileUriExposedException. It seems to be a change introduced in Android SDK 24 (link)

I read this solution: link, but I already use cordova.file.externalDataDirectory to save my PDF...

jcmag
  • 239
  • 1
  • 3
  • 14
  • Not sure about this, but I think the problem is that an external app is trying to read data from the private folder of your app where you downloaded the pdf. An app can't access the private data folder of an other app. – Kewin Dousse Nov 23 '17 at 16:33
  • ok, but do you know how I could open the pdf file my app has downloaded? – jcmag Nov 23 '17 at 16:41

0 Answers0