If you run this attachment and click on English you'll see a list of made up names. When you click the objectives it should scroll though unsecure, developing, secure depending on how well the children have achieved the objective. Earlier (once) I did get it to save and the english.csv saved onto my device in My Files/Markbook/ however this only had the headers and no content!
Now, I don't know what I've done wrong but I've moved the save code around and around and around and now it pauses everytime on that line (the StringUtils save line) and comes up with a permission error. I tried to delete the file using File.Delete("/mnt/My Files/Markbook/","english.csv")
before saving but that didn't work either!
I've put it in the pause code now because when the user presses the backkey I would like to save their changes....or at least ask them but I've tried calling the ShallWeSave from the Pause and it doesn't happen!
Can't help you with the permission error.
But if you want to prompt them to save when they press the back button you should intercept the button press.
It wrote to the folder the first time, (when it didn't already exist). How then can I get it to write to a specific folder? Or where should I been saving my csv files on the device?
However, I did use a Msgbox to find out that the File.DirRootExternal returns /mnt/sdcard/ which is where I got the path "/mnt/sdcard/My Files/Markbook/" from.
It did work once when this file didn't exist, but I don't know how to delete it so that I can save the new version.
Can't help you with the permission error.
But if you want to prompt them to save when they press the back button you should intercept the button press.
Sub Activity_KeyPress (KeyCode As Int)
Msgbox(KeyCode,"")
If KeyCode = 4 Then
Select Msgbox2("Do you want to save your changes?", "Exit Markbook", "Yes","Cancel", "No",Null)
Case DialogResponse.POSITIVE
SaveTableToCSV("mnt/sdcard/My Files/Markbook/","english.csv")
Activity.Finish
Case DialogResponse.NEGATIVE
Activity.Finish
Case DialogResponse.CANCEL
Return True
End Select
End If
End Sub
Now it crashes everytime when I choose, either Yes, No or Cancel! My foot and my laptop are about to meet become friends!!
You forgot "As Boolean" at the end of the Keypress sub.
B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean
Msgbox(KeyCode,"")
If KeyCode = 4 Then
Select Msgbox2("Do you want to save your changes?", "Exit Markbook", "Yes","Cancel", "No",Null)
Case DialogResponse.POSITIVE
SaveTableToCSV(File.DirRootExternal & "/My Files/Markbook/","english.csv")
Activity.Finish
Case DialogResponse.NEGATIVE
Activity.Finish
Case DialogResponse.CANCEL
Return True
End Select
End If
End Sub
I've even tried changing the file name. I can't seem to find any examples of people saving to a specific directory and if they don't do that where do they save things? Surely they'd be all over the place.
Applications require a "Storage" permission before they can write to the storage card.
This permission is added when you use File.DirRootExternal or File.DirDefaultExternal.
For example instead of writing:
B4X:
File.Open("/sdcard/data", "db.db")
You should write:
B4X:
File.Open(File.DirRootExternal, "data/db.db")
The required permission will be added and also the correct folder will be chosen (it is possible that the storage card folder name will be different than sdcard).