Android Question DirDefaultExternal and GetSafeDirDefaultExternal

William Hunter

Active Member
Licensed User
Longtime User
This is my first experience with the new runtime permissions. I am using KeyValueStore to store settings info in File.DirDefaultExternal. I want to make “datastore” available over SDK versions 16 to 25. Below is how I am attempting to do this. Is this the correct way, or should I handle this differently? Any help greatly appreciated.

Regards :)
B4X:
If FirstTime Then
    kvs.Initialize(File.DirDefaultExternal, "datastore")
    rp.CheckAndRequest(rp.PERMISSION_CAMERA)
    rp.CheckAndRequest(rp.PERMISSION_RECORD_AUDIO)
    rp.GetSafeDirDefaultExternal("datastore")
End If
Added this to manifest.
B4X:
<uses-permission
  android:name="android.permission.WRITE_EXTERNAL_STORAGE"
  android:maxSdkVersion="18" />
EDIT: This seems to work, but DirInternal might be just as good.
B4X:
If FirstTime Then
        Dim Dir As String = rp.GetSafeDirDefaultExternal("") 'safe dir device dependent
        kvs.Initialize(Dir, "datastore") 'init keyvaluestore
        rp.CheckAndRequest(rp.PERMISSION_CAMERA)
        rp.CheckAndRequest(rp.PERMISSION_RECORD_AUDIO)
End If
 
Last edited:
Top