Android Question Firebase Push Messaging as Widget.

BarryW

Active Member
Licensed User
Longtime User
I'm trying to create a widget app with a firebase push notification. My problem is it successfully subscribe to a topic but when message arrived it cannot capture it. Phone is just showing a notification that firebase message arrive but it is not part of my application.

Then i tried to create an app which is not a widget app. In this app firebase successfully captured by my application.

Here how i made my app.

As Erel sample on creating a widget. I create a service named Widget Service

Code: Copy
Sub Process_Globals
    Dim rv As RemoteViews
    Dim count As Int = 0
End Sub

Sub Service_Create
    rv = ConfigureHomeWidget("1", "rv", 0, "SFA Widget")
    CallSubDelayed(FirebaseMessaging, "SubscribeToTopics")
End Sub

Sub Service_Start (StartingIntent As Intent)
    If rv.HandleWidgetEvents(StartingIntent) Then Return
End Sub

Sub Service_TaskRemoved
End Sub

Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub

Sub Service_Destroy
End Sub

Sub rv_RequestUpdate
    rv.UpdateWidget
End Sub

Sub rv_Disabled
    StopService("")
End Sub

Then i create a seperate service for Firebase

Code: Copy
Sub Process_Globals
    Dim fm As FirebaseMessaging
End Sub

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

Sub Service_Start (StartingIntent As Intent)
    If StartingIntent.IsInitialized Then fm.HandleIntent(StartingIntent)
    Sleep(0)
    Service.StopAutomaticForeground
End Sub

Sub Service_Destroy
End Sub

Public Sub SubscribeToTopics
    Log("SubscribeToTopics")
    fm.SubscribeToTopic("sfa")
End Sub

Sub fm_MessageArrived (Message As RemoteMessage)
    Log("Message arrived")
End Sub

For this code i just do a logs and no notification but my phones displays a notification

Firebase setup works fine without any error on compiling and running. It just cannot capture the firebase message.
 
i see now whats happening. After installation and i add Activity.Finish to Main Module it cannot receive push notification
also when i add AddReplacement(android.intent.action.MAIN, unused_action) to manifest it also cannot receive notification.

Activity.Finish is added to Main because Erel example is like that.
AddReplacement(android.intent.action.MAIN, unused_action) is added to Manifest because i want to hide my menu icon.

any help?
 
Upvote 0
Ok sir then i will remove it from Manifest. But still when i call Activity.Finish from Main Module still cannot receive.
 
Upvote 0
Yes sir i followed it and everythings work fine except for when Im trying to do it as widget
 
Upvote 0
First you posted about an issue related to the icon hiding.
Then you posted about an issue that happened because you haven't follow the instructions.

Yes sir i followed it and everythings work fine except for when Im trying to do it as widget
I don't see how we can help you unless you provide enough information. At this point you should upload two projects:
1. The B4A project.
2. The B4J project that you use to send messages.
 
Upvote 0
Back
Top