Android Question Recover title and message from firebase

Isac

Active Member
Licensed User
Longtime User
How can I recover the title and message that comes from firebase and then insert it into a Main.EditText1.text?

B4X:
#Region  Service Attributes
    #StartAtBoot: False
    
#End Region

Sub Process_Globals
    Private fm As FirebaseMessaging
    
End Sub

Sub Service_Create
    fm.Initialize("fm")
    
End Sub

Public Sub SubscribeToTopics
    fm.SubscribeToTopic("all") 'you can subscribe to more topics
End Sub

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

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)
    Main.EditText1.text   '<---------------
      
    n.Vibrate=True
End Sub

Sub Service_Destroy

End Sub
 

Isac

Active Member
Licensed User
Longtime User
OK DonManfred no problem no one forces you ;)



B4X:
Logger connesso a:  HUAWEI BLN-L21
--------- beginning of crash
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
*** Service (firebasemessaging) Create ***
** Service (firebasemessaging) Start **
** Receiver (firebasemessaging) OnReceive **
** Service (firebasemessaging) Start **
Message arrived
Message data: {}
firebasemessaging_fm_messagearrived (java line: 157)
java.lang.IllegalArgumentException: Invalid notification (no valid small icon): Notification(pri=0 contentView=null vibrate=default sound=default defaults=0x7 flags=0x11 color=0x00000000 vis=PRIVATE)
    at android.app.NotificationManager.notifyAsUser(NotificationManager.java:318)
    at android.app.NotificationManager.notify(NotificationManager.java:293)
    at android.app.NotificationManager.notify(NotificationManager.java:277)
    at anywheresoftware.b4a.objects.NotificationWrapper.Notify(NotificationWrapper.java:281)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:191)
    at anywheresoftware.b4a.BA$1.run(BA.java:330)
    at android.os.Handler.handleCallback(Handler.java:761)
    at android.os.Handler.dispatchMessage(Handler.java:98)
    at android.os.Looper.loop(Looper.java:156)
    at android.app.ActivityThread.main(ActivityThread.java:6523)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
Your problem is right there Infront of your face written in red, read the first few lines in red extremely carefully. Once you read and understand the error message, you will move further on with your app development.

You've been a member for 4 years now, you must have developed and used the logs before, even if only in a 'hello world's app.
 
Upvote 0
Top