40155

PhoneGap open file in native app. Build via build.phonegap.com

At first:

YES, there are many solutions in StackOverflow, but non of them works in my case.

<ol> <li>I got application built in SmartGWT.mobile</li> <li>I attached config files and all needed files to this build to prepare it for PhoneGap</li> <li>Application is build via build.phonegap.com site.</li> <li>It works perfectly fine on Android 4.1.1 </li> </ol>

I want to:

<ol> <li>

Download file to local filesystem it is an PDF file - <strong>It is working fine</strong> using:

var fileTransfer = new FileTransfer(); fileTransfer.download(..... </li> <li>

Open PDF in native app (for eg. Adobe Reader) whichever is installed on android for PDFs - <strong>it is not working</strong>:

I tried:

(1)

cordova.exec("ChildBrowserCommand.showWebPage", encodeURI(theFile.toURL()) );

(2)

window.plugins.childBrowser.showWebPage(encodeURI(theFile.toURL()));

(3)

window.open(encodeURI(theFile.toURL()), '_blank', 'location=yes');

(4) even HTML5 plugin for open PDFs by firefox

</li> </ol>

All variations with "file://" without with "./" at front and so on.

childBrowser shows only white screen, each time adds "http://" at front, window.open - the same.

I finally found something interesting like WebIntent, so i did:

window.plugins.webintent.startActivity({ action: window.plugins.webintent.ACTION_VIEW, type: "application/pdf", url: encodeURI(theFile.toURL().substring(7))}, function() {}, function() {alert('Failed to open URL via Android Intent')} );

but its not working due to fact that phonegap-build not attaching class file and It can not find WebIntent Class

I declare this plugin using in config.xml:

<gap:plugin name="com.borismus.webintent.WebIntent" />

Do you know why it is not working, or what I'm doing worng ? Maybe you know other way to open file just like that in native app, it suppose to be simple

I just want my app to download and show (in native app) the PDF for user.

Answer1:

don's FileOpener version have worked on my app cordova 3.0

phonegap local plugin add https://github.com/don/FileOpener

all the xmls, plugin, etc are then added automatically.

added <strong>fileopener.js</strong> on index.html and then

window.plugins.fileOpener.open( path );

Answer2:

$("#page").on('pageshow', function(event, ui) { if(event.handled !== true) { window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem; window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail); event.handled = true; } return false; }); function fail() { console.log("failed to get filesystem"); } function gotFS(fileSystem) { console.log("got filesystem"); // save the file system for later access console.log(fileSystem.root.fullPath); window.rootFS = fileSystem.root; downloadImage(url, fileName); } function downloadImage(url, fileName){ var ft = new FileTransfer(); ft.download( url, window.rootFS.fullPath + "/" + fileName, function(entry) { console.log("download complete: " + entry.fullPath); }, function(error) { console.log("download error" + error.code); } ); }

Recommend

  • How to tell Filepicker to upload file from a native input type=“file”?
  • NSFileManager URL vs Path
  • itextsharp editor for creating tags
  • Can Mozilla's pdf.js modify PDFs?
  • PDFbox Preflight PDF/A-1b check not working properly in java version 1.8
  • Converting IDML to HTML5 thru script
  • Is it possible to know the duration of an MP3 before the entire file is downloaded?
  • How to reduce SSRS PDF Export Size
  • DocumentsDirectory in UITableView Array for Xcode 7 and Swift 2.0
  • jquery/javascript post to new window when pressing a preview button
  • Compressing a PDF document generated by coldfusion
  • Java/JavaFX: Set Swing Icon for JavaFX label
  • iphone/ipad web video only plays over 3g not Wifi
  • Getting Javascript Errors From Another Window
  • Is there any way to center certain columns in table?
  • jQuery random blockquote
  • How to read JSON-LD data from HTML in Objective-C?
  • In java, how do you retrieve images from a jar file?
  • IOS > Open URL in Safari with POST
  • Need a consistent TimePicker gizmo for mobile web site
  • MAVEN : Run Multiple Maven Project using Maven Test
  • TFS - how do I sum child task hours to parent
  • python: forcing relative imports to search from script file
  • jquery validation - waiting for remote check to complete
  • Jenkins Grails plugin does not list lastest versions of Grails
  • Iron Router: How do I send data to the layout?
  • Zoom in and out of jPanel
  • How to generate and display a QR Code in ionic 2
  • Firefox Extension - Monitor refresh and change of tab
  • Saving Changes After In-App Purchase Has Been Purchased
  • Alert pop up with LWUIT
  • Disabling Alt-F4 on a Win Forms NotifyIcon
  • How to redirect a user to a different server and include HTTP basic authentication credentials?
  • Can I make an Android app that runs a web view in Chrome 39?
  • To display the title for the current loaction in map in iphone
  • jQuery tmpl and DataLink beta
  • AngularJs get employee from factory
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • LevelDB C iterator
  • Linking SubReports Without LinkChild/LinkMaster