Phonegap how to download and open pdf file in android app

前端 未结 4 1544
囚心锁ツ
囚心锁ツ 2020-12-06 12:54

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 docu

相关标签:
4条回答
  • 2020-12-06 13:27

    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

    0 讨论(0)
  • 2020-12-06 13:36

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

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

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

    0 讨论(0)
  • 2020-12-06 13:37

    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!

    0 讨论(0)
  • 2020-12-06 13:37

    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

    0 讨论(0)
提交回复
热议问题