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
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
Your code is correct. If the camera is not needed immediately when the program starts then it is better to ask for the permission later when it is required.