Evolution-36 / cordova-plugin-file-opener2

Cordova plugin file opener based on pwlin's plugin. This plugin is updated to work with Android Oreo. This plugin was cloned because pwlin's plugin did not support writing access on Oreo.
MIT License
3 stars 4 forks source link

Opened PDF file behaviour #6

Open matiasmicheletto opened 4 years ago

matiasmicheletto commented 4 years ago

When opening a PDF file using the plugin, the pdf file reader app (I think it is Adobe) doesn't let me share the file. If I open the same file from the file manager with the same reader app, the sharing menu is showed up normally. There shoulnd't be any difference so I assume its a plugin issue when launching the pdf reader.

Here is my code:

window.resolveLocalFileSystemURL(cordova.file.externalRootDirectory, function(rootEntry) {
            rootEntry.getDirectory('MyFolder', { create: true, exclusive: false, replace: true }, function(directoryEntry) {
                directoryEntry.getFile(fileName+'.pdf', { create: true, exclusive: false, replace: true }, function(fileEntry) {
                    fileEntry.createWriter(function(fileWriter) {
                        fileWriter.onwriteend = function() {                        

                                // Open file with the plugin
                                cordova.plugins.fileOpener2.open(
                                    cordova.file.externalRootDirectory+fileEntry.fullPath, 
                                    "application/pdf", 
                                    {
                                        error : function(e){
                                            fail('Error 1: ' + e.status + ' - Error message: ' + e.message);
                                        }, 
                                        success : success 
                                    } 
                                );
                        };
                        fileWriter.onerror = function (e) {
                            fail(e);
                        };
                        pdfFile.getBuffer(function (buffer) {
                            var utf8 = new Uint8Array(buffer);
                            fileWriter.write(utf8.buffer);    
                        });
                    }, 
                    function(er){
                        fail("Error 2:" + JSON.stringify(er));
                    });
                }, 
                function(er){
                    fail("Error 3:" + JSON.stringify(er));
                });
            }, 
            function(er){
                fail("Error 4:" + JSON.stringify(er));
            });
        }, 
        function(er){
            fail("Error 5:" + JSON.stringify(er));
        });