I cut & pasted some proven code from a mature project to read some common resource files from FileDirRootExternal.
Having gained the necessary RTP for PERMISSION_WRITE_EXTERNAL_STORAGE I was surprised to find that File.ListFiles(AppDir) was returning an uninitialized List. So I tried a simple write operation...
The log error is:
The puzzling thing is that if I modify the old project code to look at the new path specified in AppDir it works perfectly.
Any ideas?
Having gained the necessary RTP for PERMISSION_WRITE_EXTERNAL_STORAGE I was surprised to find that File.ListFiles(AppDir) was returning an uninitialized List. So I tried a simple write operation...
B4X:
Sub Activity_Create(FirstTime As Boolean)
rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
If Result = False Then
ToastMessageShow("External Read/Write Permission Refused",True)
Activity.Finish
Else
Log("All OK") 'This is output every time
End If
Activity.LoadLayout("main")
AppDir = File.DirRootExternal & "/MyDir/"
File.WriteString(AppDir,"text.txt","1234") 'Error here: write permission refused
End Sub
The log error is:
java.io.FileNotFoundException: /storage/emulated/0/MyDir/text.txt: open failed: EACCES (Permission denied)
The puzzling thing is that if I modify the old project code to look at the new path specified in AppDir it works perfectly.
Any ideas?