Handling notifications in android - android

I would like to know what is best practice when operating with push notifications in particular GCM notifications. Where should I ignore the notification from the server side. That is to say the server only send notifications to active users or the client side where the server sends out notifications but the app ignores them based on whether the activity is open or closed.

It's always better to decide at the server side which devices have active users, and only send notifications to them.
The reasons:
You don't want to run any code in the client side if you are not going to do anything with the incoming GCM message, since that would just be a waste or battery life.
It's better to reduce the number of messages your server sends to GCM server, since this way, the devices that should recieve and display the notifications will recieve them faster.

Related

How to messengers receive notification messages from servers?

Currently I am working on an alert app, which receives push notifications from a server. Reading a lot about that topic on the internet lead me to firebase which can be used to achieve that.
Now I was wondering: Are Whatsapp, Signal and other messengers using firebase or do they have any other solution to receive messages from servers even if the app is not active opened?
They use push messaging. It might be firebase, it might be another provider. MQTT is popular. All any of those things do is open up a persistent socket connection to a server and listen for messages. The trick is that whatever process is doing that needs to be whitelisted from power management restrictions, because you don't want to delay your message notifications for 15 minutes.
Now if you're writing something that's supposed to be robust queueing on the server side and deduping on the client side would be a good idea. But the basics is open socket connection and block on it on a thread.

Need most reliable way to push notifications

I have an android app that uses GCM for push notifications. Lets say I need this for ambulance drivers when new calls are received. Right now there is a delay between when the server sends out the push notification and when the android device receives it, sometimes more than a minute. I've read on Stack Overflow about sending the heartbeat out, set delay_while_idle to true/false( yes I've seen both) etc...
What I need to know is if this is just how it is with GCM or if there is a way to make push notification times much more reliable. I've had suggestions of sockets, test messages etc... Because this is potentially for medical services I can't afford to have delays longer than what is absolutely necessary.
I've read that GCM notification delivery isn't guaranteed so is there a direction someone can point me to maybe do this on my own so that I can make something is guaranteed???
GCM push notifications are not reliable.
Have a look at "Pushy": https://pushy.me/
They state the following on their website:
The most reliable push notification gateway, perfect for real-time
applications.
Google Cloud Messaging simply doesn't cut it for time-sensitive,
real-time apps, due to its instability and push notification
throttling.
Pushy works by maintaining a dedicated background socket connection
using the MQTT protocol, an extremely light-weight pub/sub protocol
that consumes very little network bandwidth and battery, which makes
it perfect for mobile.
You can use it for free with up to 100 devices, so you could just give it a try to see, if it fits your needs. I didn't try it.

GoogleCloudMessages Server to Device delay

I have a server with sql database.
Also have about 100k users on android application.
What I need now is to send immediately notifications from the server to all devices.
Im researching the GCM system but as I see there`s a huge delay on the receiving side.
What I need is when I click the send button on my server,everyone device to receive it in a few seconds.
Is the delay only happening when using the HTTP connection?
Is it going to be different with the XMPP connection ?
You are trying to broadcast a message to nearly 100k users and currently xmpp downstream messaging does not support broadcasting. Use http server to send message to 1000 devices at a time. This can be improved by using multi curl. see this https://github.com/mseshachalam/GCMMessage-MultiCURL
In general the GCM is the right choice for massive broadcasting.
On the other hand the messages are not guaranteed to be delivered immediately, the delay might be up to 25(!) minutes given, that all devices have your app up and running.
See Google Cloud Messaging - messages either received instantly or with long delay for explanations why

Google Cloud Messaging without working data connectivity

Can Google Cloud Messaging deliver a notification with "zero-byte payload" to a phone that's capable of receiving voice calls and SMS, but for whatever reason has no working data connectivity at the moment?
By "zero byte", I mean that the phone would be aware that a GCM notification having no payload was sent to it by a specific sender, and could fire off an intent to that effect.
Real-world example: A burglar alarm gets triggered, and sends two push messages to the homeowner -- a zero-byte message whose meaning is implied entirely from the fact that it was sent at all, implies "something bad is happening", and can (presumably) be delivered even when data connectivity is blocked or unavailable because it (presumably) rides over the same transport layer used for SMS, and a longer push notification sent a few seconds later with additional meta-information about the situation that might only work if there's working data connectivity at the moment (so the phone could be notified, and fetch the payload from a server after establishing a conventional data session).
I've read Google's docs, but it seems like they've intentionally bent over backwards to say nothing about GCM's physical transport layer.
I would have to say "No" on that, since GCM (and pretty much everything Google does) is TCP/UDP/IP-based, there's no way it can get delivered to your phone if your phone doesn't have an active data (3G/4G/WiFi) connection.
Since the phone wouldn't have an IP-address, GCM couldn't deliver the message.
From GCM Architectural Overview:
It uses an existing connection for Google services.
No. There is no zero length message if you are using the GCM. GCM needs to aleast contain some information on what service will be recieving this message.
Notice GCM=> Google CLOUD Message . Can't be cloud if you aren't connected.
GCM is a server-push. Servers can't push to client if they aren't reachable.

Android C2DM: Determine if push notification can be delivered now

is there a way to determine, if a push notification can be delivered right now?
As far as i know its not possible, but im not sure about it.
So my scenario looks like this:
I have a android app
I have my own server
My app on my android phone should communicate with my app on my friends android phone.
Now im looking for a realtime communication framework and i guess C2DM could help me.
So lets say:
My app on phone A should write a little message to my app on phone B.
Lets assume, phone A is online and can communicate with my server. So phone A would send the message to my server, and my server would now try to deliver this message to phone B.
And thats the point, where my server would try to deliver the message to phone B via C2DM, and thats also the point, where my server needs to know, if its possible to send this message via C2DM or not. Otherwise my server should use another communication way to deliver the message, like sms or whatever.
So the point is, that i really need to know if its possible at this very moment to deliver to Phone B via C2DM (of course my server knows the C2DM Registration ID of Phone B).
Otherwise, for example if Phone B is not connected to the internet and can not receive C2DM push notifications, my server would send a sms to phone B.
Is it possible, to dertemine if phone B is online?
What i try to do is, to reach every user (if his phone is turned on). If he is online, then via C2DM, otherwise via SMS, so that the message is delivered at this very moment in any way.
Note:
I know that C2DM can store notifications and deliver the stored notifications when phone B is online, but thats not the way i want to use it. Note also, that i know (architectural) how to use C2DM. So the "message", that should be delivered from phone A to phone B will not be delivered directly in a C2DM push notification with the message text / sensitive data as message body. Of course the delivered message is only a "update message" to tell my app on phone B, that something has changed and the app should connect now to my server to get (polling) the latest state with the "text message" which has been sent from phone A to you (phone B)
is there a way to determine, if a push notification can be delivered right now?
No. There is no guarantee that a C2DM message will ever be delivered, let alone immediately.
Is it possible, to dertemine if phone B is online?
Phone B can know if it is online. If you implement a server with some sort of long-held socket connection (e.g., XMPP), that server can know if it has an open socket connection with Phone B.

Categories

Resources