Skip to content Skip to sidebar Skip to footer

Phonegap How To Download And Open Pdf File In Android App

recently i am working on a android apps build in phonegap, i am quite new with mobile development and this i smy first appsbut, and i am stuck when try to download some documents (

Solution 1:

I had the same problem as the OP and many unsuccessful approaches later I came to the following solution (tested with Cordova 3.1.0-3.3.0 & Samsung Galaxy S3 & iOS 7):

Solution

First, get the file by requesting the file system and then download it from your server with fileTransfer.download(). After completing the download call the FileOpener (which will open a pop up where to choose from apps like Adobe Reader). Note: Make sure to include the FileTransfer feature via CLI/Terminal: cordova plugin add org.apache.cordova.file

  • Navigate to your project folder
  • Open CLI/Terminal and type in: cordova plugin add https://github.com/don/FileOpener.git
  • After successful download and storage of your file on the device (see above) you open it with: window.plugins.fileOpener.open("file:///sdcard/Android/data/com.example.application/document.doc") or the appropriate path on iOS.

That's it! Good luck!

Solution 2:

Make sure you've had these lines in your manifest.xml :

<uses-permissionandroid:name="android.permission.READ_EXTERNAL_STORAGE"/><uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

You can find help here How to download a pdf file in Android?

Solution 3:

Make sure

You should install git and install file plugins(cordova 3.0+)

File and file transfer plugin

$ cordova plugin add org.apache.cordova.file $ cordova plugin add org.apache.cordova.file-transfer

Ps. Try plugin fileOpener2

https://build.phonegap.com/plugins/1117

Solution 4:

Try this to open any kind of documents from URL using following steps:

It works for me both on Android and IOS. I used it for open images and PDF files.

Android : It opens files using system apps if available, otherwise it give an error, which you can handle.

IOS : It opens files in popup like view with Done button and Option button.

It doesn't show your docs URL.

Source is available here : https://github.com/ti8m/DocumentHandler

Post a Comment for "Phonegap How To Download And Open Pdf File In Android App"