0

I am building a Cordova app for android, made up of a (large) number of files. Most of them have intenal links to pdf files such as this one:

<a class="download " target="_self" href="../res/DOC140416-1.pdf" download="DOC140416-1.pdf"><span>DOC140416-1.pdf</span></a>"

To access them from the app, I downloaded the file-opener2 plugin from GitHub. It installed nicely in the plugin folder in the newly created directory: cordova-plugin-file-opener2

I then found the following snipet which I pasted in the index.js

cordova.plugins.fileOpener2.open(
    filePath, 
    fileMIMEType, 
    {
        error : function(){ }, 
        success : function(){ } 
    } 
);

And finally I added

<plugin name="FileOpener" value="com.phonegap.plugins.fileopener.FileOpener"/>

to the config.xml.

As most of you can probably tell (stop laughin'!), tapping on the links fails miserably (though working well of vourse on my pc, since the borwsers are fitted for pdf files).

Can I get some help from you guys? Many thanks!

Needzhelp
  • 111
  • 1
  • 12
  • Hello Avijt, thanks for your answer. I know it should prompt for one way or anorher to open file, and that would ne fine. My problem is that nothing happens. Am i doing something wrong? Thank you. – Needzhelp Apr 21 '16 at 04:30

1 Answers1

0

FileOpener plugin is only to open the dialog, it can not open your PDF file. It will just prompt you in which application you want to open the file.

As you are saying it may have file types other than PDF, so you have three options.

  1. Download the file and then prompt user in which application they want to open the file by FileOpener plugin.

  2. Open the file using system's default browser to download it.

  3. Open the link in google doc viewer by passing the url.

Ref:Phonegap InAppBrowser display pdf 2.7.0

Community
  • 1
  • 1
Avijit
  • 1,253
  • 13
  • 21
  • From what I gather, there would need to be a a function call such as LINK The problem is that there are far too many links to do it by hand. Besides some links do not target a pdf file... – Needzhelp Apr 21 '16 at 14:26
  • Is that all your PDF files stored locally or it can be hosted on some other server? What plugins you have used? If you share the code in more detail then it will help. – Avijit Apr 21 '16 at 19:27
  • Thank you! I can post all this in about 12 hours (it's night here :-)) – Needzhelp Apr 21 '16 at 19:55
  • I need to pass the file path (always local) as the first parameter, – Needzhelp Apr 22 '16 at 20:32
  • $(document).on("click",'a[href$=".pdf"]',function(e){ e.preventDefault(); console.log($(this).attr('href')); }); By This you can get the href and prevent default click of anchor tags – Avijit Apr 23 '16 at 16:28
  • Hello Avijit!YOur peice of code has been very good to me. But until today I am still struggling to find how I can then use "this.href" to have fileOpener2 working. I cannot get past obtaining the full path (I do have that , I can see in in the alert)... Any idea? – Needzhelp Aug 01 '16 at 18:16