varta
varta

Reputation: 3416

Phonegap, open local Pdf file on Android 7

I have a cordova app with pdf's in it. Every year the pdf's need to be updated and there seems to be a new headache to get it working on Android.

On iOS I can open it with InAppBrowser and the relative url

cordova.InAppBrowser.open(URL,'_blank','closebuttoncaption=< Terug,toolbar=yes');

On android I used different methods, childbrowser, fileOpener2 and copying the file to externalDataDirectory

var uri = 'www/' + URL;
window.resolveLocalFileSystemURL(cordova.file.applicationDirectory +  uri, 
  function(fileEntry) {
    window.resolveLocalFileSystemURL(cordova.file.externalDataDirectory, function(dirEntry) {
      fileEntry.copyTo(dirEntry, uri.split('/').pop(), function(newFileEntry) {
        //window.open(newFileEntry.nativeURL, '_system');
        cordova.plugins.fileOpener2.open(newFileEntry.nativeURL,'application/pdf');
      });
    });
  }, function(evt) {
    alert("Problem opening catalogus \n" +JSON.stringify(evt));
    console.log(JSON.stringify(evt));
  }
);

Latest solution was using

<preference name="android-targetSdkVersion" value="23" />
<preference name="android-minSdkVersion" value="16" />

But google only excepts targetSdkVersion 26 now to the store

So any good working solutions out there?

I thought it was a common use case and simple to achieve, when I started out...

Upvotes: 0

Views: 585

Answers (1)

Milan O
Milan O

Reputation: 163

You can find an explanation and workaround here: https://github.com/apache/cordova-plugin-inappbrowser/issues/386

I hope this will be fixed with a PR soon.

Upvotes: 0

Related Questions