Sub Process_Globals
Private rp As RuntimePermissions
End Sub
Sub Globals
End Sub
Sub Activity_Create(FirstTime As Boolean)
End Sub
Sub Activity_Click
GetFileList
End Sub
Sub GetFileList
If rp.Check( rp.PERMISSION_WRITE_EXTERNAL_STORAGE) Then
For Each f As String In File.ListFiles(File.DirRootExternal)
Log(f)
Next
Else
'Allow Permission and return to this Sub
AllowPermissionToStorage("GetFileList")
End If
End Sub
#Region Check Permission
Private Sub AllowPermissionToStorage(Callback As String)
If Not(rp.Check( rp.PERMISSION_WRITE_EXTERNAL_STORAGE)) Then
If ShouldShowRequestPermissionRationale(rp.PERMISSION_READ_EXTERNAL_STORAGE) Then
Msgbox2Async("In the next dialog you should allow access to photos, media and files, because without this access the app cannot save files or access its own log files.", "Memory-Access", "OK","","", Null, False)
Wait For Msgbox_Result (Result As Int)
End If
Check_EXTERNAL_STORAGE(Callback)
End If
End Sub
Private Sub Check_EXTERNAL_STORAGE(Callback As String)
If Not(rp.Check( rp.PERMISSION_WRITE_EXTERNAL_STORAGE)) Then
rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
If Result = False Then
If ShouldShowRequestPermissionRationale(rp.PERMISSION_READ_EXTERNAL_STORAGE) Then
Msgbox2Async("You have denied access to photos, media and files. Without this access, the app cannot save files or access its own log files." & CRLF & _
"Would you like to make your selection again?", "Permission denied!", "YES", "NO", "", Null, False)
Wait For Msgbox_Result (Ret As Int)
If Ret = DialogResponse.POSITIVE Then
Check_EXTERNAL_STORAGE(Callback)
End If
Else
Msgbox2Async("You have denied access to photos, media and files. Without this access, the app cannot save files or access its own log files." & CRLF & _
"These setting can now only be changed in the app setting. Would you like to change your app settings?", "Permission denied!", "YES", "NO", "", Null, False)
Wait For Msgbox_Result (Ret As Int)
If Ret = DialogResponse.POSITIVE Then
GetPermissionSetting
End If
End If
Else
CallSub(Me, Callback)
End If
End If
End Sub
Private Sub GetPermissionSetting
Dim in As Intent
in.Initialize("android.settings.APPLICATION_DETAILS_SETTINGS","package:" & Application.PackageName)
StartActivity(in)
End Sub
Sub ShouldShowRequestPermissionRationale (Permission As String) As Boolean
Dim ctxt As JavaObject
ctxt.InitializeContext
Dim ActivityCompat As JavaObject
ActivityCompat.InitializeStatic("android.support.v4.app.ActivityCompat")
Return ActivityCompat.RunMethod("shouldShowRequestPermissionRationale", Array(ctxt, Permission))
End Sub
#End Region