Android Question FirebaseNotifications - manuplations

Tayfur

Well-Known Member
Licensed User
Longtime User
Hello;

I used FirebaseNotifications lib. and I used sample code
https://www.b4x.com/android/forum/threads/firebasenotifications-push-messages-firebase-cloud-messaging-fcm.67716/

SERVICE name is FirebaseMessaging

B4X:
#Region  Service Attributes
    '#StartAtBoot: False
    #StartAtBoot: False
    #ExcludeFromLibrary: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private fm As FirebaseMessaging
    'https://www.b4x.com/android/forum/threads/firebasenotifications-push-messages-firebase-cloud-messaging-fcm.67716/
End Sub

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.
    fm.Initialize("fm")
    Log("service create")
End Sub

Sub Service_Start (StartingIntent As Intent)
    Log("service start")
    If StartingIntent.IsInitialized And fm.HandleIntent(StartingIntent) Then Return
End Sub

'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Log("app error")
    Return True
End Sub

Sub Service_Destroy

End Sub

Public Sub SubscribeToTopics
    Log("sub topics")
    fm.SubscribeToTopic("general") 'you can subscribe to more topics
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("X-"&Message.GetData.Get("title"), "X-"&Message.GetData.Get("body"), Main)
    n.SetInfo("X-"&Message.GetData.Get("title"), "X-xxxx", Main)
   
    n.Notify(1)
End Sub

after
I sent with firebase tools on web .
it s like underbelow

firebase-web-setting.png




And Result is under below. Mycode results and real screen result is not same.
My code is
n.SetInfo("X-"&Message.GetData.Get("title"), "X-xxxx", Main)
but, result is diffrent on device!!!

How can i change message before notifige showing process

Screenshot.jpeg
 

Tayfur

Well-Known Member
Licensed User
Longtime User
I
See the tutorial: FirebaseNotifications - Push messages / Firebase Cloud Messaging (FCM)

You shouldn't use Firebase console to send the messages. Only the B4J code.
tired your example. I changed Key
it is log :
B4X:
Waiting for debugger to connect...
Program started.
[jobname=fcm, success=true, username=
, password=, errormessage=, target=class b4j.example.main
, taskid=1, req=anywheresoftware.b4h.okhttp.OkHttpClientWrapper$OkHttpRequest@6f539caf, tag=java.lang.Object@79fc0f2f
, httputils2service=null]
{"message_id":6993436539599866157}
Program terminated (StartMessageLoop was not called).

but i cant recive messages. ???
where is my wrong?
 
Upvote 0

Tayfur

Well-Known Member
Licensed User
Longtime User
Last edited:
Upvote 0

Tayfur

Well-Known Member
Licensed User
Longtime User
I solved it, it my error.

Soryyy @Erel ; I spend your time on vacant times


I must addd Starter module code like underlines

B4X:
#Region  Service Attributes
    '#StartAtBoot: False
    #StartAtBoot: False
    #ExcludeFromLibrary: True
#End Region

Sub Process_Globals
    'Private fm As FirebaseMessaging
    'https://www.b4x.com/android/forum/threads/firebasenotifications-push-messages-firebase-cloud-messaging-fcm.67716/
End Sub

Sub Service_Start (StartingIntent As Intent)

End Sub

Sub Service_TaskRemoved
    'This event will be raised when the user removes the app from the recent apps list.
End Sub

'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub

Sub Service_Destroy

End Sub
'Starter service

Sub Service_Create
    Log("starter service crate")
   CallSubDelayed(FirebaseMessaging, "SubscribeToTopics")
End Sub
 
Upvote 0
Top