Can't Save - Permissions Error

School Boy Error

Member
Licensed User
Longtime User
Hi,

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!

I think I've confused myself now...
 

School Boy Error

Member
Licensed User
Longtime User
You can only write to folders under File.DirInternal or DirInternalCache or on the storage card.

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?

Thanks MiniDemonic, I'll take a look at that.
 
Upvote 0

School Boy Error

Member
Licensed User
Longtime User
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.
 
Upvote 0

School Boy Error

Member
Licensed User
Longtime User
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.

more info http://www.b4x.com/forum/basic4andr.../9233-intercepting-back-button.html#post51197

I tried that using this code:

B4X:
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!!
 
Upvote 0

MiniDemonic

Member
Licensed User
Longtime User
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
 
Upvote 0

School Boy Error

Member
Licensed User
Longtime User
I have tried saving it to another folder, I've tried it with the file in there, I've tried an empty folder. It did work once but not again since!!!

The code keeps pausing at this line:

B4X:
   StringUtils1.SaveCSV2("/mnt/sdcard/My Files/Markbook/","english.csv", ",", list1, headers)

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.
 
Upvote 0

MiniDemonic

Member
Licensed User
Longtime User
http://www.b4x.com/forum/basic4andr...lmost-there-permission-problem.html#post39800

Try this.

Also found this.

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).
 
Last edited:
Upvote 0
Top