- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
$( "#pgImport" ).on("pageshow", function(event) { importFiles(); });
which calls the following function :-
function importFiles() { var ft = new FileTransfer(); ft.download( "http://10.10.10.6/downloads/operator.txt", // what u download "/sdcard/test.txt",// this is the filename as well complete url function(entry) { alert("success"); alert(JSON.stringify(entry)); }, function(err) { alert(err); alert(JSON.stringify(err)); } ); alert("Import Files"); }
However JSHints tells me that FileTransfer is not defined.
Other than icluding the plugins in the Hybrid Mobile App settings, and linking to cordova.js in my html file, do I need to to anything else?
All help greatly appreciated.
- Tags:
- HTML5
- Intel® XDK
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
File Transfer will work on actual device, you can either build app and test or use App Preview using test tab or on USB connected device using debug tab.
Make sure you have checked the File, File Transfer and Device plugins under project settings -> plugins
You can use this test code to make sure deviceready is firing:
function onDeviceReady(){ alert("deviceready") } document.addEventListener("deviceready", onDeviceReady, false);
All File Transfer initialization should be done after deviceready is fired.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm obviously doing something wrong because it's still not working.
I have added your test code to the bottom of my html file, and it is firing - alerting me that the device is ready before doing anything else in the app.
Here is the order of linked script files, (and your suggested test code), at the base of my <body> :-
<script src="intelxdk.js"></script> <!-- phantom library, needed for XDK api calls --> <script src="cordova.js"></script> <!-- phantom library, needed for Cordova api calls --> <script src="xhr.js"></script> <!-- phantom library, needed for XDK CORS --> <script src="js/app.js"></script> <!-- for your event code, see README and file comments for details --> <script src="js/init-app.js"></script> <!-- for your init code, see README and file comments for details --> <script src="xdk/init-dev.js"></script> <!-- normalizes device and document ready events, see file for details --> <script> function onDeviceReady(){ alert("deviceready") } document.addEventListener("deviceready", onDeviceReady, false); </script>
Is this order correct?
jquery and jquery mobile scripts are linked in <head>.
The code I have an issue with is in app.js but is not called until the required page is shown:-
function importFiles() { var ft = new FileTransfer(); ft.download( "http://10.10.10.6/downloads/operator.txt", // what u download "/sdcard/test.txt",// this is the filename as well complete url function(entry) { alert("success"); alert(JSON.stringify(entry)); }, function(err) { alert(err); alert(JSON.stringify(err)); } ); alert("Import Files"); } $( "#pgImport" ).on("pageshow", function(event) { importFiles(); });
Again, any help advice greatly appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
here is test code I used to check:
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, user-scalable=no"> <script src="cordova.js"></script> <script> function onDeviceReady(){ alert("deviceready") } document.addEventListener("deviceready", onDeviceReady, false); function fileDownload(){ try{ var ft = new FileTransfer(); ft.download( "http://www.google.com/robots.txt", // what u download "/sdcard/test.txt",// this is the filename as well complete url function(entry) { alert("success"); alert(JSON.stringify(entry)); }, function(err) { alert(err); alert(JSON.stringify(err)); } ); } catch(err){alert(err.message)} } </script> </head> <body> <br> <br> <button onclick="fileDownload()">File Download</button> </body> </html>
http://10.10.10.6/downloads/operator.txt is not working so I used some other url
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page