- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I am working on an Application with IntelXDK that needs to be able to remember some data. It's really simple data (name of an object + its adress) so I wanted to store it inside a text-file.
I've been having a few problems with that though.
Is there a possibility to just create a memory.txt file inside my application's www-directory (where there are already Dictionaries like Images/Galleria/etc. and then have access to it inside the programm?
I've been trying to use the cordova-file plugin to access the file, but I don't know which location I have to use for it?
This is what I'm doing right now: (error: file not found)
document.addEventListener('deviceready', onDeviceReady, false); function onDeviceReady() { function readFromFile(fileName, cb) { var pathToFile = cordova.file.dataDirectory + fileName; console.log(pathToFile); window.resolveLocalFileSystemURL(pathToFile, function (fileEntry) { fileEntry.file(function (file) { var reader = new FileReader(); reader.onloadend = function (e) { cb(JSON.parse(this.result)); }; reader.readAsText(file); }, errorHandler.bind(null, fileName)); }, errorHandler.bind(null, fileName)); } var fileData; readFromFile('printer_setup.txt', function (data) { fileData = data; }); }
Help would be very much appreciated :) ,
Konrad
- Tags:
- HTML5
- Intel® XDK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I don't know if there is a difference, but using localStorage works for me in real apps deployed to Android and iOS devices.
For example I use it to give the user the option to remember its login:
Save data
localStorage.setItem('leche_userid',usuarioid); localStorage.setItem('leche_pass',$("#i_password").val());
Recover data
$("#i_email").val(localStorage.getItem('leche_userid')); $("#i_password").val(localStorage.getItem('leche_pass'));
I think you may be confident it will work. I'm not sure, but I'm remembering that the device debug clears caches and storages when it runs.
Regards,
Diego
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Konrad,
Take a look at this blog post, it discuss some alternatives to store data in hybrid apps.
http://gonehybrid.com/dont-assume-localstorage-will-always-work-in-your-hybrid-app/
Besides its title, I think it may have useful information for you.
Regards
Diego
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hey Diego!
Thank you for your response.
Your solution works for me on the Intel XDK-Simulation and if I debug the HTML-File inside Google Chrome. It also seems really simple and elegant, I like it very much.
Sadly it doesn't work when I debug the Application on my nexus 9 device (doesn't show any error on the Console though..). Do you have any idea why? The App has permission to use the file-system.
I want to create a hybrid application for mobile devices.
Konrad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Konrad,
localStorage is not working on device? You mean using Debug connecting your phone to XDK or installing an APK?
Regards,
Diego
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I tried it while debugging in Intel XDK when connected to the Nexus.
Is there a difference to installing the APK and then running the application?
Regards,
Konrad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I don't know if there is a difference, but using localStorage works for me in real apps deployed to Android and iOS devices.
For example I use it to give the user the option to remember its login:
Save data
localStorage.setItem('leche_userid',usuarioid); localStorage.setItem('leche_pass',$("#i_password").val());
Recover data
$("#i_email").val(localStorage.getItem('leche_userid')); $("#i_password").val(localStorage.getItem('leche_pass'));
I think you may be confident it will work. I'm not sure, but I'm remembering that the device debug clears caches and storages when it runs.
Regards,
Diego

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page