I use File.DirRootExternal and File.DirDefaultExternal in my apps and I want to implement the RuntimePermissions.
To the DirDefaultExternal I use GetSafeDirDefaultExternal("") and works fine.
How I can change this code to use the RuntimePermissions?
in a test i used this
GetSafeDirDefaultExternal have a parameter subfolder
B4X:
Dim rp As RuntimePermissions
Log(rp.GetSafeDirDefaultExternal(""))
File.WriteString(rp.GetSafeDirDefaultExternal(""),"test.txt","Hallo")
If File.Exists(rp.GetSafeDirDefaultExternal(""),"test.txt") =False Then
ToastMessageShow("attachment file not found",False)
End If
Dim rp As RuntimePermissions
rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE) 'it create a event, see quick info
Log(File.DirRootExternal)
Log("PERMISSION_WRITE_EXTERNAL_STORAGE:" & rp.Check(rp.PERMISSION_WRITE_EXTERNAL_STORAGE))
You can call this code whenever you want to access the external storage:
B4X:
Dim rp As RuntimePermissions
rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
If Result Then
'access here
Else
'no permission
End If
Thanks! I understand now.
If I use File.DirRootExternal, I will see a dangerous permission in the list permissions, but not if I use only the File.GetSafeDirDefaultExternal("").
Thanks, but I want avoid to getting permission on the maximum amount of options I can.
Will be nice if I could do it with DirRootExternal, but I will prefer GetSafeDirDefaultExternal(""), that no need permission.