Phonegap How To Download And Open Pdf File In Android App
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
Solution 4:
Try this to open any kind of documents from URL using following steps:
- install this plugin : cordova plugin add https://github.com/ti8m/DocumentHandler
use this code :
handleDocumentWithURL(function() { console.log('success'); }, function(error) { console.log('failure'); if (error == 53) { console.log('No app that handles this file type.'); } }, 'http://www.example.com/path/to/document.pdf');
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"