Android Question Notifications permission

asales

Expert
Licensed User
Longtime User
when the application is first launched
How are you doing this?

In my apps I put this code in then B4XPage_Created sub
B4X:
Dim ph As Phone
If ph.SdkVersion > 32 Then  'Android 13+ (33)
    If (kvs.GetDefault("shownotification", True) = True) Then GetPermissionNotification
End If
The GetPermissionNotification shows a Msgbox2Async to the user confirm if will activate or not the notifications and set the "shownotification" to false in the KVS.
 
Upvote 0

asales

Expert
Licensed User
Longtime User
B4X:
Sub GetPermissionNotification
    Msgbox2Async("Deseja ativar as notificações?", "", "ATIVAR", "", "Cancelar", Null, True)
    Wait For Msgbox_Result (Result As Int)
    If Result <> DialogResponse.POSITIVE Then Return

    Wait For (CheckAndRequestNotificationPermission) Complete (HasPermission As Boolean)  'same from the example

    kvs.Put("shownotification", False)
End Sub
 
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
Can you please tell me if it is possible to read the SetInfo values after they are set in line #7 of the example before the notification is executed?
B4X:
Private Sub Button1_Click
    Wait For (CheckAndRequestNotificationPermission) Complete (HasPermission As Boolean)
    If HasPermission Then
        Dim n As Notification
        n.Initialize
        n.Icon = "icon"
        n.SetInfo("This is the title", "and this is the body.", Main) 'Change Main to "" if this code is in the main module.
        n.Notify(1)
    Else
        Log("no permission")
        ToastMessageShow("no permission", True)
    End If
End Sub
 
Upvote 0

Alessandro71

Well-Known Member
Licensed User
Longtime User
In my apps I put this code in then B4XPage_Created sub
B4X:
Dim ph As Phone
If ph.SdkVersion > 32 Then  'Android 13+ (33)
    If (kvs.GetDefault("shownotification", True) = True) Then GetPermissionNotification
End If

out of curiosity, why are you using the Created rather than the Appear sub?
the user can revoke permission in the Android settings after the app was started.
using the Appear you will have a chance to get this, because at the next app foreground event, permissions will be checked
 
Upvote 0
Top