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?
B4X:
MyDir = File.DirRootExternal & "/commom/"
Thanks advance for any tips.
 

MarkusR

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

MarkusR

Well-Known Member
Licensed User
Longtime User
oh sorry i misread this part
To the DirDefaultExternal

i guess
B4X:
    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

Erel

B4X founder
Staff member
Licensed User
Longtime User
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
 
Upvote 0

asales

Expert
Licensed User
Longtime User
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

MarkusR

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

asales

Expert
Licensed User
Longtime User
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
Top