Android Question Remote notification

Nicolás Cieri

Active Member
Licensed User
Hi,

The remote notifications from my server to my B4a App. always when I clicked the notification, the app open on "main", can I change this activity default in the server?

I think this is only a parameter.

Note: The notification is created on the server.

Thanks.
 

DonManfred

Expert
Licensed User
Longtime User
can I change this activity default in the server?
No.
BUT. The Notification which you are seeing is generated BY YOUR APP when the message arrives.
Check your fm_MessageArrived Event sub

Here you are creating the Notification.

You can change the destination of your Notification....

Post your fm_MessageArrived code
 
Upvote 0

Nicolás Cieri

Active Member
Licensed User
The problem is this.. I received in both, "Foreground" and "Background",.. In foreground i can set the badge number of icon of the app. but if the notification is in background... I can see the "System tray" notification, but not update the badge of the Application Icon.


 
Upvote 0

Nicolás Cieri

Active Member
Licensed User
B4X:
Sub fm_MessageArrived (Message As RemoteMessage)

    If Message.GetData.Get("action") = "upd" Then
       
        Dim badge As ShortcutBadger
        badge.Initialize
        badge.applyCount(Message.GetData.Get("badge"))
     End If
End Sub
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
How are you sending the Notification?

Here the example code from the Tutorial. It shows how to create the notification and it uses Main. (you also can set any other activity)
B4X:
Sub fm_MessageArrived (Message As RemoteMessage)
   Log("Message arrived")
   Log($"Message data: ${Message.GetData}"$)
   Dim n As Notification
   n.Initialize
   n.Icon = "icon"
   n.SetInfo(Message.GetData.Get("title"), Message.GetData.Get("body"), Main)
   n.Notify(1)
End Sub

The other notification you see from the system is bound to your firebase project id respectively to your Packagename.
The system uses your packagenames starting-intent to start your app from the notification. This is your Main activity per default.

If your app is started from main then you can check the startingintent and forward the user to another activity if you want.
 
Upvote 0

Nicolás Cieri

Active Member
Licensed User
Yes, I know that.
But when it is "System tray" in Background this code does not run.

Reach the application in the Main Activity, that is not the problem.

The problem is to change the "Badge Number" in Background.
 
Upvote 0

Nicolás Cieri

Active Member
Licensed User
I am using my own system in .Net for sending notifications.

fm_MessageArrived ...
This event is triggered in foreground.
But not in the background (although I receive the notification by system).
 
Upvote 0

Nicolás Cieri

Active Member
Licensed User
You are absolutely right Erel !.

Using the code of B4j works in foreground and background.

If I use my .Net code, foreground works perfect, in the background I only receive the system notification but it doesn't execute "fm_MessageArrived"

Any idea what it could be ?, apparently my code is totally equivalent to that of B4j.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…