Phonegap how to download and open pdf file in android app

前端 未结 4 1547
囚心锁ツ
囚心锁ツ 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: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!

提交回复
热议问题