Hello, I'm trying to get a permission for writing to contacts at runtime. This fails, because rp.CheckAndRequest won't ask me for the permission and Sub Activity_PermissionResult is not called. Here's a very simple example that demonstrates the problem:
On my Samsung Galaxy S7, when I click on the Label the OS won't ask for the permission, I always get "No Permission". Moreover the MsgBox disappears immediately after showing up.
Can anybody tell me what's wrong with this code, please?
Thank you.
B4X:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim rp As RuntimePermissions
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private AskForPermission As Label
Dim PermissionResult As Boolean
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("Layout1")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub AskForPermission_Click
rp.CheckAndRequest("WRITE_CONTACTS")
If PermissionResult = True Then
Msgbox("Permission granted", "")
Else
Msgbox("No Permission", "")
End If
End Sub
Sub Activity_PermissionResult (Permission As String, Result As Boolean)
If Permission = rp.PERMISSION_WRITE_CONTACTS Then
PermissionResult = Result
End If
End Sub
On my Samsung Galaxy S7, when I click on the Label the OS won't ask for the permission, I always get "No Permission". Moreover the MsgBox disappears immediately after showing up.
Can anybody tell me what's wrong with this code, please?
Thank you.