1

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 1

1

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:

  1. 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
  2. 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
  3. 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
  4. 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.

Sign up to request clarification or add additional context in comments.

5 Comments

I understand your suggestion but I have over 200 inputs/values. Any other simple way to go about this?
Well I was thinking of putting local http handler (mini webserver) on the phone so I could just point to localhost and thought someone had figured out the same but didnt find such project. I am going to play around with it and if I come up with something useful, I will let you know
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.
@momo Hi momo , Have u incorporated this in your app .. CAn i get an small sample code for acheving this
@user899641: If you wrote your comment as an answer, you would've been awarded credit by now. :-) Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.