Android Question FirebaseNotifications: msg box with notification

kelvo01

Member
Licensed User
Longtime User
when i recevie a notification Erel make notification ok.
if i click on a notification the app re-take control.
i what to put a msg box with notification.

How ?
 
Last edited:

kelvo01

Member
Licensed User
Longtime User
I try this, but don't work:

in main.bas
Sub Process_Globals
Dim lastFBMtitle As String
Dim lastFBMbody As String
...

Sub Activity_Resume
Dim in As Intent
in = Activity.GetStartingIntent
If in.HasExtra("Notification_Tag") Then
Log(in.GetExtra("Notification_Tag")) 'Will log the tag
Msgbox(lastFBMbody,lastFBMtitle)
End If
End Sub

In FirebaseMessaging
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.SetInfo2(Message.GetData.Get("title"), Message.GetData.Get("body"),"Notification_Tag", Main)

n.Notify(1)

Main.lastFBMtitle=Message.GetData.Get("title")
Main.lastFBMtitle=Message.GetData.Get("body")
End Sub
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
Please use code tags like this example:

B4X:
Sub fm_MessageArrived (Message As RemoteMessage)
   Log("Message arrived")
   Log($"Message data: ${Message.GetData}"$)
   Log("ID: " & Message.MessageId)
   Log("From: " & Message.From)
   Log("Collapse: " & Message.CollapseKey)

   Log(Message.GetData)

    Dim messmap As Map
    messmap=Message.GetData
 
    Log(messmap.Get("data"))
 
    Dim n As Notification
    n.Initialize
    n.Icon = "icon"
    n.OnGoingEvent=False
    n.Light=True
    n.SetInfo2(messmap.Get("data"),"New message!","Info", "")
    n.Vibrate=False
    n.Notify(1)

    CallSub2(Main,"MyMsgBoxSub",messmap.Get("data") 'This calls a sub in your Main Activity. Here call msgbox.... with the data
 
End Sub
 
Upvote 0

kelvo01

Member
Licensed User
Longtime User
So i try this code, but don't work :'(

B4X:
' in main.bas
Sub Activity_Resume
    Dim in As Intent
    in = Activity.GetStartingIntent
    If in.HasExtra("InfoTag") Then
        Log(in.GetExtra("InfoTag")) 'Will log the tag    
      End If
End Sub

Sub MessaggiMsg (inMap As Map)
    Log(inMap.GetKeyAt(0))
    Log(inMap.GetValueAt(0))
    Msgbox("text ...","text ...")
   
End Sub

' in service
Sub fm_MessageArrived (Message As RemoteMessage)
   Log("Message arrived")
   Log($"Message data: ${Message.GetData}"$)
   Log("ID: " & Message.MessageId)
   Log("From: " & Message.From)
   Log("Collapse: " & Message.CollapseKey)

   Log(Message.GetData)

    Dim messmap As Map
    messmap=Message.GetData
    Log(messmap.Get("data"))
    Dim n As Notification
    n.Initialize
    n.Icon = "icon"
    n.OnGoingEvent=False
    n.Light=True
    n.SetInfo2(messmap.Get("data"),"New message!","InfoTag", "")

    n.Vibrate=False
    n.Notify(1)

    CallSub2(Main,"MessaggiMsg",messmap.Get("data"))
   
End Sub
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

kelvo01

Member
Licensed User
Longtime User
Don't work ...
when i open the notification the sub "MessaggiMsg" don't start :(
 
Last edited:
Upvote 0

kelvo01

Member
Licensed User
Longtime User
"fm_MessageArrived will be raised whenever a message is received"

i think the problem is here!

the log aren't displayed ...
Log("Message arrived")
Log($"Message data: ${Message.GetData}"$)

why in my app the sub fm_MessageArrived don't start ?
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
Question:

- Your receive the message in fm_MessageArrived or not? (= does the debugger stop here? When you send the message, is it "successful" in Job.Done?)
- You want to know if the Activity was started via notification? This is done this way:

B4X:
Sub Activity_Create(FirstTime As Boolean)
   
    Dim in As Intent
    in = Activity.GetStartingIntent
    If in.HasExtra("Notification_Tag") Then
       'do something (msgbox or something else)
    End If

The code checks "why" the Activity has started. Here it checks if it was from a notification.
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
Check that the prefix in the initialization of your FirebaseMessaging object is correct (ie: matches the "fm" part of "fm_MessageArrived") - eg:
B4X:
fm.Initialize("fm")

- Colin.
 
Upvote 0

kelvo01

Member
Licensed User
Longtime User
update: I receive the message and the icon in the upper bar but on the icon app don't appear the number.

before in starter.bas i miss this:

B4X:
Sub Service_Create
    'This is the program entry point.
    'This is a good place to load resources that are not specific to a single activity.
    CallSubDelayed(FirebaseMessaging, "SubscribeToTopics")
End Sub
 
Upvote 0

An Schi

Well-Known Member
Licensed User
Not sure if i understand correctly - but if you want to have the number on the icon of the homescreen, this is not included in firebase nor notification.
This is called a badge. search the forum, there is a library for this, but i'm not sure if it works correctly on all devices.
 
Upvote 0
Top