I have a simple Android App using simple js, jquery mobile and phonegap that has form data that I would like to write to CSV on /sdcard. I can not figure out the best way to do this. It needs to write locally to CSV since the device will not have internet access. Each time the form is filed out, each CSV file name must be unique, containing 'CompanyName' field. I have searched everywhere and cannot figure this out. Help Please...
1 Answer
I have implemented similar things (read/write data via mobile web-app with no internet connection). You might be able to utilize the same approach that I took which is using custom ContentProvider in Android to save your data. Provided the data is not large, this approach should work. If that is the case then you could do the following:
- Create custom content URI scheme such as content://myuri. This is a neat feature of Android since I could call this URI from the built-in browser including even using links in your HTML page. It basically treat this URI as any other http:// uri
- In the implementation for writing you could devise the URL as content://myuri/writeData/input1=value1/input2=value2/input3=value3 and so on. I am not sure if there is a limitation in ContentProvider for the length of URI accepted by the ContentProvider which is why I put the caveat above. I don't have a large form when I tried this approach last time
- In the implementation of your extension of ContentProvider, you need to override the function public ParcelFileDescriptor openFile (Uri uri, String mode) and have them interpret the URI that is given in step #2. The implementation should be parsing the URI and then write the data to the CSV as you intended
- You can get this data back using different URI scheme such as content://myuri/getData/[theFileID] which now in the implementation of #3 above, you will do the reverse and return the CSV data to your mobile web-app
Let me know if you have any question.
5 Comments
user899641
I understand your suggestion but I have over 200 inputs/values. Any other simple way to go about this?
user899641
I found an app that does exactly what I'm trying to do. It's called Form Builder. It has the option to export data to CSV. I have to figure out how they did that.
user3383301
@momo Hi momo , Have u incorporated this in your app .. CAn i get an small sample code for acheving this
Michael Scheper
@user899641: If you wrote your comment as an answer, you would've been awarded credit by now. :-) Thanks!