How to check the Notification Received Status from Firebase in my Server - android

I have setup push notification service with Firebase, I'm sending notifications with the help of REST API, notification are received by different clients at different times based on their token.
There can be different reasons when a user will not be able to receive the notifications for e.g. he don't have Internet connection.
So I need the status from client side that either the notification is received on the device or not or it is in pending state? with the notification details
I need to get this info and save it in my server. How this can be achieved?

Related

Sending push notifications to different users at device time with FCM

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.

How to continuously make a http request and respond with push notification if data is available

I'm developing an app in which I wanted to implement some notifications features for the user. Every user notification is saved in a back end sql database. What I've done so far is to create a Android service in which after a certain delay, an HTTP request is made to check if database has new notifications for the user by processing its json reply and notify the user if something is available.
After some research I've done, I have come to conclusion that this in not battery-friendly and I "have" to use Push Notifications using some service like gcm or fcm.
So my problem is now this:
How to properly make a request to the database every for example 1
sec. and check if any notification is available and THEN make a
push notification so that the device is triggered to fetch the
notifications themselves from the database?

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.

How to handle functionality (in a good approach/Better way) , if Push Notification not delivered to My device.?

While reading some article about push notifications, I got to know that push notifications will not be delivered 100% to the device.
In this case how can handle my application functionality in a better way ,
why I am asking is because in the push notification. I will be sending the last updated record id based on that I will be updating data /information in my device.
If I am not receiving any push notification then I have to manage this situation based on some time slot I have to keep on checking the server to fetch the record if i am doing in this way then it will affect for battery because keep on checking method whether some data as update or not
Which we will be the good way to handle this situation, I need a logic for better way of doing.
First of all - On contrary to documentation, Push Notification is working consistently for us.
Secondly, the way I would design this by keeping track of receipt of push notification. For instance:
Server Sent the Push payload to APNS and note down the time.
Client received the Push Notification and make a server call & inform the receipt of notification and pulls the record details.
If server did not receive a notification of push receipt within X period then trigger another push notification. OR
For any further service call, Server can also inform client of missed notification confirmation. Based on this client can trigger the server pull for that record. So, its not a timer based pull but a more informative decision based on data.
PS: From your description I believe you are sending push payload not exceeding 256 bytes.

How to get push notification on/off status programmatically to send it to my webserver?

I have implemented push notification in my app sucessfully using GCM.
I Am using my dotnet webserver to send push message to my app vai GCM Server.
I have stored GCM Registered Id in database on my server.
Now I want to check that if user has manually disable/off the notification for my app (by going through setting), so that i can send request to my webserver that not to send push message to that device by removing GCM ID from database(unregistering).
I know push messages are delivered to my app and are ignored if notification is off but my problem is that my app is going to be used by more 100000 users/devices and if only few of them are using notification on, then there is unnecessary traffic of sending push messages over 100000 devices/users.
So is there any way to know the status of the notification on/off programmatically so that i can send request to deregister the app on my web server?
I have googled and found that there is no way to find it out, so is any one has other solution for my scenario.
Please help me on this as i am stuck on this from last couple of days.
Thanks in advance,
Ketan Bhangale
Store user status in SharedPreference and check status while displaying notification.
same status you can store on your server and sort list of sender with status.
The ability to disable an app’s notifications is only for devices currently running Android 4.1+ Jelly Bean. Also there seems to be no documented way to know the value for notification flag(check box) in default application settings.
Simply you need to maintain that manually. Say first create a web service for update "notification setting" . The app will send the value for notification say "true" or "false" as chooses by user fro our app settings menu.
Now at server side store that value for notification_flag corresponding to that user in your db.
Before sending the notification to the user on your desired even(as per app requirement when to send notification) , check first the value of the flag before firing the send notification msg on the device id for that user.
Also finally to be more reliable at app end too , check the value for that flag before showing the notification in the app when the message arrived.

Categories

Resources