Android Question firebase notifications with time constraints

Hello everybody :)
I have a small question. I am using Firebase to send notifications, can I somehow limit them in time? For example send / receive message from 8 am to 8 pm?

I will be glad to any answer

best regards
 

KMatle

Expert
Licensed User
Longtime User
If you send data messages, there won't be an automatic notification. So you app must throw an own one. Here you can decide if it's the right time or store it to show it later.

Data message:

B4X:
Dim m As Map = CreateMap("to": $"/topics/${Top}"$)
    Dim data As Map = CreateMap("data": datastring)
    m.Put("data", data)
    Dim jg As JSONGenerator
    jg.Initialize(m)
    Job.Tag=jg
    Log(jg.ToString)
    Job.PostString("https://fcm.googleapis.com/fcm/send", jg.ToString)
    Job.GetRequest.SetContentType("application/json;charset=UTF-8")
    Job.GetRequest.SetHeader("Authorization", "key=" & API_KEY)
 
Last edited:
Upvote 0
If you send data messages, there won't be an automatic notification. So you app must throw an own one. Here you can decide if it's the right time or store it to show it later.

Data message:

B4X:
Dim m As Map = CreateMap("to": $"/topics/${Top}"$)
    Dim data As Map = CreateMap("data": datastring)
    m.Put("data", data)
    Dim jg As JSONGenerator
    jg.Initialize(m)
    Job.Tag=jg
    Log(jg.ToString)
    Job.PostString("https://fcm.googleapis.com/fcm/send", jg.ToString)
    Job.GetRequest.SetContentType("application/json;charset=UTF-8")
    Job.GetRequest.SetHeader("Authorization", "key=" & API_KEY)

Тhanks for the answer!

It remains to find out how to implement a time period check :D
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
No problem

if the application is not running

Correct.

1. So you could throw a notification directly but without sound & light "at night" using the notification builder library (browse for it)
2. Store the messages at night to a file and if the user opens the app, show them.
3. Another one was to create a foreground service which has a timer. This keeps the device awake and consumes many battery power (not recommended) or Android will kill it. There ARE ways but as Android is user orientated (not a pc) not really waht you should do.

If you need more ideas, just post what kind of messages you process and what the user does with it (just read?)
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
If you send data messages, there won't be an automatic notification. So you app must throw an own one. Here you can decide if it's the right time or store it to show it later.

Data message:
I recommend using the code from the B4J sending tool. It is very similar to the code you posted, but will also work with iOS devices.
 
Upvote 0
Top