pwlin / cordova-plugin-file-opener2

A File Opener Plugin for Cordova
MIT License
314 stars 587 forks source link

Android fixes #176

Closed imgx64 closed 6 years ago

imgx64 commented 6 years ago

Various Android fixes. To verify it doesn't break anything, I tested opening a PDF and installing an APK on Android 4.1, 4.4, 5.0, 6.0, and 7.0.

boboldehampsink commented 6 years ago

I'm going in an endless loop when opening a PDF. Nothing happens except getting thousands of these in the logs:

10-24 06:18:23.706 3210-3273/com.company.app D/EGL_emulation: eglMakeCurrent: 0xae8e8b80: ver 2 0

Tested on 5.1 (API 22)

imgx64 commented 6 years ago

@boboldehampsink Where is the PDF file located? And do you have a default application that opens PDF or are you getting the "Open with..." page?

boboldehampsink commented 6 years ago

The PDF is located in the cache directory. It's not opening at all (no open with and no default application). This might be due to not having any capable pdf app installed at all.

imgx64 commented 6 years ago

How are you calling it? This code works on my Android 5.0 device:

function log(a) {console.log(a);};
resolveLocalFileSystemURL(cordova.file.cacheDirectory, function(directory) {
  directory.getFile('test.pdf', {}, function(file) {
    cordova.plugins.fileOpener2.open(
      file.toURL(),
      'application/pdf',
      {
        success: log,
        error: log,
      }
    );
  }, log);
}, log);
boboldehampsink commented 6 years ago

Okay, tested on simulator with 5.1 without pdf apps didn't work, but so didn't the original version. Tested on a real device with 5.0 works, but I don't see any difference with the original version.

imgx64 commented 6 years ago

I don't see any difference with the original version.

Well, the sample code I posted above does not work on Android <6 when using version 2.0.19 of this plugin (the PDF app starts, but it can't read the file). With this PR, it works correctly.

If there's no app to open PDF, the error callback is called and you can ask the user to install a PDF app.

boboldehampsink commented 6 years ago

Ok, I can confirm that opening a file on < 6.0 does not work in the original code, and works with this code. Thanks for this.

skar3 commented 6 years ago

Guys how can i use this fix on my app?

boboldehampsink commented 6 years ago

cordova plugin add https://github.com/imgx64/cordova-plugin-file-opener2.git

skar3 commented 6 years ago

Thank you,this PR works on Android 5.1.1, 6.0.1, 7.1.1 (real devices)

pwlin commented 6 years ago

Thank you very much for your contributions.