Android Question b4a 12.2 receivers with firebase notifications - icon persists

tufanv

Expert
Licensed User
Longtime User
Hello,

I have updated to b4a 12.2 to change firebasenotifications service to receivers. It looks to work without problem. Only problem is, when the app is on background and notification received, even if I click on the notification to launch the app, app icon and notification stays on notification panel. It sohuld be removed after read. Am I handling something wrong?

this is my receivers messagearrived sub:

B4X:
Sub fm_MessageArrived (Message As RemoteMessage)
    Log("Message arrived")
    Log($"Message data: ${Message.GetData}"$)
    Dim n2 As Notification
    n2.Initialize2(n2.IMPORTANCE_DEFAULT)
    n2.Icon = "icon"
    n2.SetInfo2(Message.GetData.Get("title"), Message.GetData.Get("body"),Message.GetData.Get("ilgili"), Main)
    n2.Notify(1)
    Main.notitite=Message.GetData.Get("title")
    Main.notitext=Message.GetData.Get("body")
    If Main.isactive Then
        LogColor("acikken geldi",Colors.Yellow)
        CallSub(Main, "notiac")
    End If
End Sub
 

JCO

Active Member
Licensed User
Longtime User
I'm no expert on notifications, but I believe that adding
B4X:
n2.AutoCancel=True
should do the trick
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
I'm no expert on notifications, but I believe that adding
B4X:
n2.AutoCancel=True
should do the trick
I don't think this is the correct way because it behaves odd when I use this code. When I click on notificaiton first, it does not open then it opens but doesn't execute corretly etc..
 
Upvote 0

JCO

Active Member
Licensed User
Longtime User
Try using NB6. (Reference it in the libraries)


Needs NB6:
Sub fm_MessageArriveds (Message As RemoteMessage)
    Log("Message arrived")
    Log($"Message data: ${Message.GetData}"$)
    Dim n2 As Notification
    Dim n6 As NB6
    Dim nIcon As Bitmap
   
    nIcon = LoadBitmapResize(File.DirAssets, "icon.png", 24dip, 24dip, False)

    n6.Initialize("default", Application.LabelName, "DEFAULT").SmallIcon(nIcon)
    n6.AutoCancel(True)

    n6.BigTextStyle("Title", "Short txt", "Long text")
    n2 = n6.Build("Title", "Body", "aTag", Main)
   
    n2.Notify(1)
   
    Main.notitite=Message.GetData.Get("title")
    Main.notitext=Message.GetData.Get("body")
    If Main.isactive Then
        LogColor("acikken geldi",Colors.Yellow)
        CallSub(Main, "notiac")
    End If
End Sub

Note the icons are treated differently. It needs to be converted to bitmap
 
Upvote 0
Top