I know that FCM messages are sent to devices corresponding to FirebaseInstanceId.getInstance().getToken() and on onMessageReceived() the FCM messages are handled according to the need of the User. But if the app is not running and with all the background limitations in Oreo how the OS knows that a message has arrived?
how the OS knows that a message has arrived?
There is a socket connection between the phone and google's FCM server. This connection is shared between all apps on the phone that use FCM.
See here
When you ask FCM to deliver a message to your phone ABC and to the app with id XYZ, google's server will send some data to phone ABC. The FCM component on the phone then finds the app with id XYZ (it has to look up the correct app first because this connection might also receive data for other apps) and deliver the message to id.
This is managed by google so naturally the process doesn't suffer from background restrictions, assuming you set the right priority for your FCM message.
Related
I have implemented a server which will send some alerts to android devices. For most of devices, Notifications are getting received. However there are few devices to which notifications could not be delivered?
I would like to know if there is way to get list of such a devices for which notifications delivery was failed?
Does GCM provides this data(List of devices for which notifications delivery was failed)?
However there are few devices to which notifications could not be delivered.
If your devices don't receive notifications, try the following workarounds:
Make sure you've set your SENDER ID you've received from Google correctly.
Make sure your device was registered with Google's GCM service correctly.
Make sure you are sending the push to the correct reg id you've received from Google, and that you didn't receive an error from Google GCM service.
If you set the delay_while_idle = 1, the message won't reach the device if it's idle (off, offline, locked screen, etc...). Change it to delay_while_idle = 0 if you want your wakelock permission to make any difference.
Some times it takes time for the push to arrive, but if there is too much time, then there is a problem. Check what's the time_to_live of the push you've sent.
I would like to know if there is way to get list of such a devices for which notifications delivery was failed?
Based also from this thread, Google only provide some statistics that are available on the android developer console. This only shows the number of messages and registrations.
You would have to implement your own data collection, which could be done fairly easily. You could record the time & id of each message sent and have your android client report back to your server with the time of message receipt. You could then store the data on your server and query as needed.
You can check this View & diagnose Google Cloud Messaging (GCM) statistics link to know your GCM message status.
I am testing an apps. Push notification is working fine in our server environment. But in client's environment, large amount of Android devices (NOT ALL) do not receive any push notification.
What is the possible factor? the return status form GCM is "Failed"
the return status from GCM is "Failed"
Android Device which is Receiving push must be online, if not GCM will pool notifications till it reached a mark of 100, It will start clearing the pool if more notification arrives at their end
large amount of Android devices (NOT ALL) do not receive any push notification.
Did you check you have correct GCM ID with each device? If not The device will never receive a single notification. If your device have a valid GCM ID and have received some notification then it must be a problem in connecting with the device.
Also device must have Latest Play Services installed to get the notification on board
I'm currently working on an Android messaging app and GCM is utilized for notifications.
When the device of the recipient, that'd already be registered on GCM, is off, what exactly happens? Does GCM wait until the device is back online? If so, does the device send a message to say it's alive, or does GCM keep pinging the device? Or does GCM continually send the message until success? Either way, how long can the message persist on the GCM server when the device is offline?
Any direction would be helpful.
As per the documentation
Google enqueues and stores the message in case the device is offline.
When the device is online, Google sends the message to the device.
Detailed Explanation
If the device is not connected to GCM, the message will be stored until a connection is established.
how long can the message persist on the GCM server when the device is offline
If the device never gets connected again the message will eventually time out and be discarded from GCM storage. The default timeout is 4 weeks, unless the time_to_live flag is set.
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.
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.