Android Question FirebaseNotifications works on the emulator does not work on the phone.

MichalK73

Well-Known Member
Licensed User
Longtime User
Hello.
As the topic. Messages sent from B4J Server. When I run B4A applications on the NOX Player emulator, the notification is coming. The same application running on the phone, notifications do not come. I have a confirmation to send a message.
As for me, the difference is the NOX Player Android version 4.4.2 and the 6.0 phone.
The message from the console firebase comes to emulate as well as phone.

I do not know where else to look for a problem.
 

DonManfred

Expert
Licensed User
Longtime User
Start with uploading your project. Without seeing your project we hardly can´t answer.
 
Upvote 0

MichalK73

Well-Known Member
Licensed User
Longtime User
Yes the application works on the phone but does not reach the notification.

Code from server
B4X:
'Handler class
Sub Class_Globals
    Private const API_KEY As String = "my api key"
End Sub

Public Sub Initialize
    'StartMessageLoop
End Sub

Sub Handle(req As ServletRequest, resp As ServletResponse)
    Dim topic As String = req.GetParameter("topic")
    Dim title As String = req.GetParameter("title")
    Dim body As String = req.GetParameter("body")
 
    SendMessage(topic,title,body)
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 m As Map = CreateMap("to": $"/${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")
    Job.GetRequest.SetHeader("Authorization", "key=" & API_KEY)
End Sub


Sub JobDone(job As HttpJob)
    Log(job)
    If job.Success Then
        Log(job.GetString)
    End If
    job.Release
    'StopMessageLoop '<-- non ui app only
End Sub

log
B4X:
Waiting for debugger to connect...
Program started.
init mysql
maj 29, 2017 1:55:16 PM com.mchange.v2.log.MLog
INFO: MLog clients using java 1.4+ standard logging.
maj 29, 2017 1:55:16 PM com.mchange.v2.c3p0.C3P0Registry
INFO: Initializing c3p0-0.9.5.2 [built 08-December-2015 22:06:04 -0800; debug? true; trace: 10]
2017-05-29 13:55:17.070:INFO::main: Logging initialized @1861ms
2017-05-29 13:55:17.482:INFO:oejs.Server:main: jetty-9.3.z-SNAPSHOT
2017-05-29 13:55:17.517:INFO:oejsh.ContextHandler:main: Started o.e.j.s.ServletContextHandler@7d70d1b1{/,file:///C:/robole/new/serwer/Objects/www,AVAILABLE}
2017-05-29 13:55:17.535:INFO:oejs.AbstractNCSARequestLog:main: Opened C:\robole\new\serwer\Objects\logs\b4j-2017_05_29.request.log
2017-05-29 13:55:17.573:INFO:oejs.ServerConnector:main: Started ServerConnector@7a9273a8{HTTP/1.1,[http/1.1]}{0.0.0.0:1234}
2017-05-29 13:55:17.574:INFO:oejs.Server:main: Started @2365ms
Emulated network latency: 100ms
true
maj 29, 2017 1:56:17 PM com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource
INFO: Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 20000, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, contextClassLoaderSource -> caller, dataSourceName -> 1hge9h79onbnkheu7uecl|1e81f4dc, debugUnreturnedConnection...
[jobname=fcm, success=true, username=
, password=, errormessage=, target=[api_key=BlAvwy0z, dateutils=null, httputils2service=null
, main=null]
, taskid=1, req=anywheresoftware.b4h.okhttp.OkHttpClientWrapper$OkHttpRequest@214b199c, tag=java.lang.Object@20d3d15a
, httputils2service=null]
{"message_id":8804783453444665769}
[jobname=fcm, success=true, username=
, password=, errormessage=, target=[api_key=z, dateutils=null, httputils2service=null
, main=null]
, taskid=2, req=anywheresoftware.b4h.okhttp.OkHttpClientWrapper$OkHttpRequest@14a2f921, tag=java.lang.Object@3c87521
, httputils2service=null]
{"message_id":7694480921155132659}
 
Last edited:
Upvote 0

MichalK73

Well-Known Member
Licensed User
Longtime User
The situation looks like this.
ASUS Tablet with Android 4.4.2 - notifications come.
Old Samsung G2 Mini 4.0.4 - notifications come.
XIAOMI redmi 3S MIUI8 Android 6 - notifications do not come.

How do you think it is persmisions Andorid 6 or MIUI ??
 
Upvote 0

MichalK73

Well-Known Member
Licensed User
Longtime User
Example server and b4a. On XIAOMI with MIUI Android 6 does not come notifications on each other come.
If you send a message from the Firebase console the message to MIUI is coming.
Firebase Console Settings Screen
 

Attachments

  • fcm.zip
    7.7 KB · Views: 267
  • screen firebase.png
    screen firebase.png
    65.8 KB · Views: 294
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I'm not sure whether it is related or not but when you send a request in a B4J server app you must start and stop a message loop:
B4X:
Private Sub SendMessage(Topic As String, Title As String, Body As String)
   'StartMessageLoop
   Dim Job As HttpJob
   Job.Initialize("fcm", Me)
   Dim m As Map = CreateMap("to": $"/topics/${Topic}"$)
   'Dim m As Map = CreateMap("to": $"/${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")
   Job.GetRequest.SetHeader("Authorization", "key=" & API_KEY)
   StartMessageLoop
End Sub


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

Other than that the code looks correct. As a test try to send with the B4J project from the tutorial.
If you are unable to solve it then delete the firebase project and create a new one.
 
Upvote 0

MichalK73

Well-Known Member
Licensed User
Longtime User
Wow.
2 notifications came but title and body is "null". 3 can not send the server turned off.
B4X:
Waiting for debugger to connect...
Program started.
init mysql
maj 30, 2017 11:56:04 AM com.mchange.v2.log.MLog
INFO: MLog clients using java 1.4+ standard logging.
maj 30, 2017 11:56:04 AM com.mchange.v2.c3p0.C3P0Registry
INFO: Initializing c3p0-0.9.5.2 [built 08-December-2015 22:06:04 -0800; debug? true; trace: 10]
2017-05-30 11:56:04.752:INFO::main: Logging initialized @1227ms
2017-05-30 11:56:05.006:INFO:oejs.Server:main: jetty-9.3.z-SNAPSHOT
2017-05-30 11:56:05.028:INFO:oejsh.ContextHandler:main: Started o.e.j.s.ServletContextHandler@3cb1ffe6{/,file:///C:/robole/new/serwer/Objects/www,AVAILABLE}
2017-05-30 11:56:05.031:INFO:oejs.AbstractNCSARequestLog:main: Opened C:\robole\new\serwer\Objects\logs\b4j-2017_05_30.request.log
2017-05-30 11:56:05.051:INFO:oejs.ServerConnector:main: Started ServerConnector@4abdb505{HTTP/1.1,[http/1.1]}{0.0.0.0:1234}
2017-05-30 11:56:05.051:INFO:oejs.Server:main: Started @1527ms
Emulated network latency: 100ms
true
[jobname=fcm, success=true, username=
, password=, errormessage=, target=[api_key=AAUBlAvwy0z, dateutils=null, httputils2service=null
, main=null]
, taskid=1, req=anywheresoftware.b4h.okhttp.OkHttpClientWrapper$OkHttpRequest@49070868, tag=java.lang.Object@6385cb26
, httputils2service=null]
{"message_id":7741973144917212464}
Worker ended (class com.jobway.task_security)
[jobname=fcm, success=true, username=
, password=, errormessage=, target=[api_key=AABlAvwy0z, dateutils=null, httputils2service=null
, main=null]
, taskid=2, req=anywheresoftware.b4h.okhttp.OkHttpClientWrapper$OkHttpRequest@473b46c3, tag=java.lang.Object@516be40f
, httputils2service=null]
{"message_id":5943410130731112086}
Program terminated (StartMessageLoop was not called).
 
Upvote 0

MichalK73

Well-Known Member
Licensed User
Longtime User
StartMessageLoop is in Main.
I changed JobDone and now all messages come but I do not have the title or body text just 'null'

B4X:
Sub JobDone(job As HttpJob)
    Log(job)
    If job.Success Then
        Log(job.GetString)
    End If
    job.Release
    StopMessageLoop '<-- non ui app only
    StartMessageLoop
End Sub
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
StartMessageLoop is in Main.
I changed JobDone and now all messages come but I do not have the title or body text just 'null'
But you dont want to answer the question you got????
Start with using the B4J program from the example. Does it send properly the messages to all devices?

Edit: Ok, overlapped :D
 
Upvote 0

MichalK73

Well-Known Member
Licensed User
Longtime User
OK. I found a spell in my program and I am working.
m.Put("date": data) -> m.Put("data": data)
All messages come, Chinese MIUI has been defeated.:D

Thank you all
 
Upvote 0
Top