Android Question Can't sent push notifications

appie21

Active Member
Licensed User
Longtime User
Hello

I have search all forms but I can't find a solution

I try too sent a notification with a button

I looks like I am logged in but i get this error
Here is the code

B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region
#BridgeLogger: True
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Layout1")
    Starter.analytics.SendEvent("login", CreateMap ("additional parameter": 100))
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Private Sub SendMessage(Topic As String, Title As String, Body As String)
    Dim Job As HttpJob
    Job.Initialize("fcm", Me)
    Dim m As Map = CreateMap("to": $"/topics/${Topic}"$)
    Dim data As Map = CreateMap("title": Title, "body": Body)
    m.Put("data", data)
    Dim jg As JSONGenerator
    jg.Initialize(m)
    Job.PostString("https://fcm.googleapis.com/fcm/send", jg.ToString)
    Job.GetRequest.SetContentType("application/json;charset=UTF-8")
    
    
    Job.GetRequest.SetHeader("Authorization", "key=" & "key" )
End Sub


Sub JobDone(job As HttpJob)
    Log(job)
    If job.Success Then
        Log(job.GetString)
    End If
    job.Release
End Sub


Sub Button1_Click
    SendMessage("Topic" ,"hi"," how are you")
    
End Sub

and here is the errror
B4X:
[errormessage=, httputils2service=null, jobname=fcm
, password=, req=anywheresoftware.b4h.okhttp.OkHttpClientWrapper$OkHttpRequest@5e8a6a, success=true
, tag=java.lang.Object@e696b5b, target=class com.avestudio.noti.main, taskid=2
, username=]
{"message_id":6277805898007252715}


I have add to my manifest
Firebase Base
Google Play Services Base
Firebase Analytics
Firebase Notifications
Firebase Auth

I can also sent notifications from my console!

But i want sent it from the app with the button
 

appie21

Active Member
Licensed User
Longtime User
I also use the library
Core
FirebaseNotifications
FirebaseAnalytics
Okhttp
Json
Okhttputils2

Are that the right ones?
 
Upvote 0

Emme Developer

Well-Known Member
Licensed User
Longtime User
I don't understand what is your error.. Last log means that message was send without any error. Where you see an error?
 
Upvote 0

appie21

Active Member
Licensed User
Longtime User
I get no notifiication on any device (i used more (from one I sent it to others))
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
and here is the errror
Which error?
[errormessage=, httputils2service=[/COLOR]null, jobname=fcm
, password=, req=anywheresoftware.b4h.okhttp.OkHttpClientWrapper$OkHttpRequest@5e8a6a, success=
true
, tag=java.lang.Object@e696b5b, target=class com.avestudio.noti.main, taskid=2
, username=]
{
"message_id":6277805898007252715}

success = true suggests the job finished without error.
 
Upvote 0

appie21

Active Member
Licensed User
Longtime User
Log(job) give

B4X:
[errormessage=, httputils2service=null, jobname=fcm
, password=, req=anywheresoftware.b4h.okhttp.OkHttpClientWrapper$OkHttpRequest@4fa9ff8, success=true
, tag=java.lang.Object@d43dcd1, target=class com.avestudio.noti.main, taskid=2
, username=]
[errormessage=, httputils2service=null, jobname=fcm
, password=, req=anywheresoftware.b4h.okhttp.OkHttpClientWrapper$OkHttpRequest@4fa9ff8, success=true
, tag=java.lang.Object@d43dcd1, target=class com.avestudio.noti.main, taskid=2
, username=]

But why did i not get a notification then?
 
Upvote 0

Emme Developer

Well-Known Member
Licensed User
Longtime User
Log(job) give

B4X:
[errormessage=, httputils2service=null, jobname=fcm
, password=, req=anywheresoftware.b4h.okhttp.OkHttpClientWrapper$OkHttpRequest@4fa9ff8, success=true
, tag=java.lang.Object@d43dcd1, target=class com.avestudio.noti.main, taskid=2
, username=]
[errormessage=, httputils2service=null, jobname=fcm
, password=, req=anywheresoftware.b4h.okhttp.OkHttpClientWrapper$OkHttpRequest@4fa9ff8, success=true
, tag=java.lang.Object@d43dcd1, target=class com.avestudio.noti.main, taskid=2
, username=]

But why did i not get a notification then?
The problem is not in send code. Maybe is in the message received. Try to upload a small example
 
Upvote 0

appie21

Active Member
Licensed User
Longtime User
ok here is my receive code

Module : Firebbasemessaging

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("general") 'you can subscribe to more topics
    Log( fm.token)
End Sub

Sub Service_Start (StartingIntent As Intent)
    If StartingIntent.IsInitialized And fm.HandleIntent(StartingIntent) Then Return
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)
End Sub

Sub Service_Destroy

End Sub
 
Upvote 0
Top