Android Question several runtime permissions

peacemaker

Expert
Licensed User
HI, All

Erel's code do not work at my Android 8 emulator - just False result without the second permission dialog. First permission isrequested OK.
Several permissions are required.

upd. PERMISSION_READ_CONTACTS and PERMISSION_WRITE_CONTACTS do not work one by one.
And PERMISSION_WRITE_CONTACTS does not worik without PERMISSION_READ_CONTACTS first.

Seems, android.permission.WRITE_CONTACTS cannot be granted at all ;(, but why
 
Last edited:

peacemaker

Expert
Licensed User
Solved such way:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Permissions.Initialize
    Permissions.Add(Starter.rp.PERMISSION_READ_CALL_LOG)
    Permissions.Add(Starter.rp.PERMISSION_READ_CONTACTS)
    Permissions.Add(Starter.rp.PERMISSION_WRITE_CONTACTS)
    

End Sub

Sub Activity_Resume
    For Each permission As String In Permissions
        If Starter.rp.Check(permission) = False Then
            Sleep(100)
            Starter.rp.CheckAndRequest(permission)
            Wait For Activity_PermissionResult (permission As String, Result As Boolean)
            Log(permission)
            If Result = False Then
                ToastMessageShow("No permission: " & permission, True)
                'Activity.Finish
                Starter.rp.CheckAndRequest(permission)
                Sleep(100)
                Return
            End If
        End If
    Next
    Activity_AfterPermission
End Sub
 
Top