Android Question Help required. NB6 Receiving 2 notifications simultaneously [Solved]

Anser

Well-Known Member
Licensed User
Longtime User
Whenever I send FCM Notification, on the device I receive 2 notifications.

  • One is the real notification with all the content that I send. Perfect
  • The second one appears with just the app name, it is not dismissable by swiping. To remove this notification, either I will have to restart the device or uninstall the app
Any hint what could be the reason of this second unwanted notification reaching the device ?

Whenever FCM message reaches the device, I call a Service to handle FCM Messages. For eg in firebaseMessaging Service
B4X:
Sub fm_MessageArrived (Message As RemoteMessage)
'   Log("Message arrived")
'   Log($"Message data: ${Message.GetData}"$)

    CallSubDelayed2(FcmNotifications,"ProcessNotifications",Message)

End Sub

In the FcmNotifications service I call the NB6 as follows
B4X:
Small_Icon = LoadBitmapResize(File.DirAssets, "applogo.png", 24dip, 24dip, False)

nb.Initialize("default", Application.LabelName, "DEFAULT").AutoCancel(True).SmallIcon(Small_Icon)
nb.LargeIcon( LoadBitmapResize(File.DirAssets, "applogo.png", 256dip, 256dip, True)   )

'From the Message identfy the notification type

If Message.GetData.ContainsKey("NotficationTag")    Then
    cNotficationTag = Message.GetData.Get("NotficationTag")
End If

nb.Build(cSubject, cMsg, cNotficationTag, TheActivity).Notify(nNotificationCount)
nNotificationCount = nNotificationCount + 1
StopService("") 'Not sure whether this line is really required or not

Any help will be appreciated
 

Anser

Well-Known Member
Licensed User
Longtime User
Solved : https://www.b4x.com/android/forum/threads/automatic-foreground-mode.90546/#content
Had to update the code in the FirebaseMessaging Service
From
B4X:
Sub Service_Start (StartingIntent As Intent)
    If StartingIntent.IsInitialized And fm.HandleIntent(StartingIntent) Then Return
End Sub
To
B4X:
Sub Service_Start (StartingIntent As Intent)
    If StartingIntent.IsInitialized Then fm.HandleIntent(StartingIntent)
    Sleep(0)
    Service.StopAutomaticForeground 'remove if not using B4A v8+.
End Sub
 
Upvote 0
Top