Dim permissionOk As Boolean = False
Do While permissionOk = False
Wait for (CheckNotificationPermission) complete(status As Boolean)
If status = False Then ' Tell user why permissions are required
Dim msg As String = "The App will ask permission to use notifications." & CRLF & _
"These notifications are required for the Centre to communicate with your phone and are only used within the APP." & CRLF & _
"Your notification information is not disclosed to any third parties!" & CRLF & _
"IMPORTANT: You must allow this permission for the App to run correctly."
Msgbox2("Msg", msg, "Notification permission", Array("OK")) 'TODO Why can't we use xui.MsgBoxAsync()?
Wait For Msg_Click (ButtonText As String)
End If
App.RegisterUserNotifications(True, True, True) ' Register notications (ask permission if required)
App.RegisterForRemoteNotifications
' Tried to put Sleep(1000) to slow things down but it don't work!
Wait for (CheckNotificationPermission) complete(status2 As Boolean)
' This is the problem on the fist pass it always returns false!!!!
If status2 = True Then ' Check permissions again and if not allowed warn the user or ask to go to settings.
permissionOk = True
Else
Dim msg As String = "This App will not run correctly without notifications permission." & CRLF & _
"You can go settings and allow Notifications or " & CRLF & _
"remove and re-install, then allow notifications when asked."
Msgbox2("Msg", msg, "Notification permission", Array("OK", "Settings")) 'TODO Why can't we use xui.MsgBoxAsync()?
Wait For Msg_Click (ButtonText As String)
If ButtonText = "Settings" Then
' see https://www.b4x.com/android/forum/threads/open-default-settings-app.51115/#content
If App.OSVersion >= 8 Then
App.OpenURL("app-settings:")
End If
End If
End If
Loop
#End If