Sending push notifications to different users at device time with FCM - android

I want to send a Push notification to different users at different time. The time will be devise time not server time.
For example -
I want to send a push notification to 'Ajay' at 8AM of device time - 'Good Morning Ajay'
I want to send a push notification to 'Gargee' at 2PM of device time - 'Have a wonderful day'
How do I receive the device time before sending the push notification?

You can't schedule notification on mobile side.
Notification messages don't execute your application code when your app is in the background. All messages sent from the Firebase console are Notification messages. So you can't currently use the Firebase console for what you are describing. So, you can send Data messages from your app server which can trigger background execution of code. You can manage the notification scheduling on your app server Using cronjob.
Otherwise, You can write cloud function for notification scheduling...

You can take the support of local notification here. You can either fire local notification or you can use DispatchQueue.main.asyncAfter to make an API call for saving the device time and also fire the push notification accordingly.

Related

How can I send notification in same time everyday - OneSignal

How can I send a push notification to my android phone with OneSignal
example I want to send automatic message at 6.00am everyday.
How can I implement it?
You can do it by running cron job on server side.
It's so simple : just set cron to start everyday on 6 am and run the command to send push notif message to all fcm_tokens which are registered already.
I suggest you to queue the messages for getting better result.

Schedule a Notification after app was closed for 5 days

I want to send the "We miss you" notification to the users who haven't user my app in more than 5 days. Can this be done with Firebase notifications?
I haven't noticed any options when creating a new notification that can see if the app wasn't used or anything similar, so I'm wondering is it possible to retrieve the timestamp of when the app was last accessed and schedule a notification (maybe locally?) using the said timestamp?
You can use implement ActivityLifecycleCallbacks.To know how to implement refer -Automatically log Android lifecycle events using ActivityLifecycleCallbacks?
Once you implement ActivityLifecycleCallbacks you will get callback whenever any of the activity is interacted by the user.
You can send this timestamp to the server everytime user interacts with your app.
The server can maintain 5 min timeout logice and send a push notification to the device.
On receiving the push notification your app can show notification to the user.

Android: Have PushNotifications an income-timestamp?

we are using the Gcm Push Notification Server from our externel Java Project to send push notifications to an Android Phone.
On this phone there is an app running that reacts on this notification. The app needs to know when the push notification arrived at the phone (in order to calculate a 120sec timer beginning at this point of time).
Is there a possibility in the andorid app to find out when the push notification arrived...some kind of creation/imcome/recieved timestamp?
Thx
Try System.currentTimeMillis() in your GcmListenerService's onMessageReceived() method.

Mass push notification sending in some intervals

I am trying to figure out how Facebook / Twitter sends push notifications like "You have 20 new followers"I don't know how to call it but i want to learn the underlying algorithm of this in Android. Please help, Thanks !
On Android you can execute your code before actually showing a push notification. They could simply send a push notification to all devices with an identifier, then the app can make a request to the server and get the needed information in order to show the push notification.
They can also send one push notification per device, as they can associate the push notification key with the user login, and the server would fire a push notification every time there is an event that demands a push notification.
But there are also other ways of doing this, for example, they can, for example run locally in background and create a local notification when the app decides it is necessary.

Should i use push notifications for all new instant messages

I am using a custom php webserver for an im program to send push messages, for now i can send push notifications to mobile phone but i am not sure about how to use it properly.
By this i mean should i send all messages as push notifications, is it possible to do that? Is there any limitations about push notification's size? Or should i start a timer to check new messages after first notification and finish the timer when the activity is closed?
So what would be the most proper way to get instant messages from the server?
For Android the limitation on the push notification size is 4k. If your messages are smaller than that, you can use push notifications for sending all the content.
However, delivery of push notifications is not guaranteed, so it's a better practice to use if as a means for the server to notify the app that new data is available, especially when it's not running in the foreground. The app then calls the server to retrieve the data.
When the app is in the foreground, you can poll the server periodically for new data.

Categories

Resources