Android Question Firebase Notification

Noorul HAQUE

Member
Licensed User
Dear Team,

I facing two problems with Firebase Notification,

1st Problem

Firebase notification is only happening if my application is in background working mode, ie, If I am in my App, I am not receiving any notification.

2nd Problem

I have defined newMessage as global variable and in FireBaseMessaging module I have code as below where I have set newMessage as True,

Now my problem if I access this variable from Main Module, its value still false even after notification message. My requirement isto set this variable trueif any notification arrives, I also tried to save this value in a text file upon receiving notification that also not working.

Please support me on this, thanks in advance.

B4X:
Sub Process_Globals
   Dim newMessage As Boolean
   newMessage = false
End Sub
 
Sub fm_MessageArrived (Message As RemoteMessage)
    Dim n As Notification
    If Message.GetData == Null Or Message.GetData.Get("title") == Null Then
       Return
    End If
    n.Initialize
    n.Icon = "icon"
    n.SetInfo(Message.GetData.Get("title"), Message.GetData.Get("body") , Main)
    Main.newMessage=True
    n.Notify(1)
End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Firebase notification is only happening if my application is in background working mode, ie, If I am in my App, I am not receiving any notification.
1. How are you sending the messages?

2. Where is newMessage declared? In Main module or FirebaseMessaging module?
If the process is killed before the main activity is started then the value will be lost. You should save the value in a file.
 
Upvote 0

Noorul HAQUE

Member
Licensed User
Dear Erel

Thanks alot for your reply

1 . Now I am sending messages through Firebase console directly. I mean from Google Firebase website

2) newMessage is declared in main module,
Also I tried to write some thing in txt file in
fm_MessageArrived function, that also not working

Thanks
 
Upvote 0

Noorul HAQUE

Member
Licensed User
1. You need to use the B4J code.

2. In which way it doesn't work? The file is not created.


1) I will try b4J and I will update you
2) for writing in text file upon Message Arrival not working, the value is not updating

B4X:
Sub fm_MessageArrived (Message As RemoteMessage)
   Dim n As Notification
   If Message.GetData == Null Or Message.GetData.Get("title") == Null Then
           Return
    End If
    n.Initialize
    n.Icon = "icon"
    n.SetInfo(Message.GetData.Get("title"), Message.GetData.Get("body") , Main)
    WriteIni1("NewMsg","1",File.DirInternal,"Settings.ini")
    n.Notify(1)
End Sub

Sub WriteIni1(mykey As String,myvalue As String,fPath As String,filename As String)
  Dim Map1 As Map
  Map1.Initialize
  If File.Exists(fPath,filename) Then
                 '
                 ' 
  Else
    File.WriteMap(fPath, filename, Map1)
  End If
  Map1 = File.ReadMap(fPath,filename)
  Map1.Put(mykey, myvalue)
  File.WriteMap(fPath, filename, Map1)
End Sub
 
Upvote 0
Top