Android Question [Solved] File.DirRootExternal and RuntimePermissions

asales

Expert
Licensed User
Longtime User
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?
Code: Copy
MyDir = File.DirRootExternal & "/commom/"
Thanks advance for any tips.
 
in a test i used this
GetSafeDirDefaultExternal have a parameter subfolder
Code: Copy
    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
 
Upvote 0
oh sorry i misread this part
To the DirDefaultExternal

i guess
Code: Copy
    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))
 
Last edited:
Upvote 0
You can call this code whenever you want to access the external storage:
Code: Copy
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
 
Upvote 0
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("").
 
Upvote 0
dangerous permission
99% apps have this in play store ...
it is not really dangerous, more the risk someone get private data.
dangerous if apps using the same file name.
 
Upvote 0
99% apps have this in play store ...
it is not really dangerous, more the risk someone get private data.
dangerous if apps using the same file name.
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.
 
Upvote 0
Back
Top