Android C2DM: Determine if push notification can be delivered now - android

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.

Related

How Android Oreo Knows that an FCM Message has arrived?

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.

How does SMS work (with Android devices)?

We are working on a app based on Google's Rich Messaging Platform (RCS) and I'd like to ask some specific questions pertaining to how SMS is delivered into Android devices.
Questions for the matter of understanding:
Are SMS messages delivered into the Android OS or the messaging app?
Are SMS messages being pushed (ie. Push Notifications) into the Android OS or messaging app? If not, is it pulled - and how?
Do MMS work the same way as SMS, in terms of how messages are delivered?
Important Question:
If we are developing an RCS app to replace SMS. Is it possible to deal with receiving SMS directly? That is, interaction with SMS would completely bypass the Android OS and/or another (default) messaging app.
EDIT - added the following questions:
This post says we can listen to incoming SMS/MMS messages. So, here's a question:
Can our app be the only sole app to listen for SMS/MMS messages?
If the answer to the above question is no, then (after the user reads the message on our app), can our app send a message to the other SMS messaging app(s) to remove the batch count and set the message to read?
If our app is NOT using Direct Boot, will SMS/MMS be lost since they cannot be delivered, whether or not our app is the sole SMS/MMS app?
And, this question for the matter of understanding:
From what I understand now is the SMS/MMS are part of the telephony system, while RCS is NOT. Could you confirm my understanding is correct?
Thanks!
To the best of my knowledge, this is how the SMS works on Android:
Are SMS messages delivered into the Android OS or the messaging app?
SMS messages are sent to the Android OS as they are part of the telephony/cellular system. They are definitely not pushed to any particular messaging app as the incoming message comes from the cellular provider to the device (aka the OS/firmware) directly. The messaging app a user interacts with is simply a "front" for displaying and interacting with the user to send/show messages at they are received. You can actually change the default messaging app on Android which further demonstrates that SMS is actually part of the OS.
Are SMS messages being pushed (ie. Push Notifications) into the
Android OS or messaging app? If not, is it pulled - and how?
Much like an incoming phone call, SMS messages are "pushed" to the device but not in the way you may be familiar with like Push Notifications (i.e. GCM). The concept of a Push Notification is something that exists on the IP layer; that is, it's a service that runs on the Internet. The kind of push a device receives for SMS messages is part of the telephony system. This is why, for instance, devices can still receive SMS with mobile data turned off but can't receive notifications for a Facebook message.
Do MMS work the same way as SMS, in terms of how messages are
delivered?
Yes, they work essentially in the same way as described above except they have some additional protocol for how they handle the data that is received from the cellular network to fetch things like images. The data is still transmitted on this telephony network and not over Internet (for the most part). There are implementations now of MMS that may piggyback off the Internet to fetch and load images quicker but that may be carrier specific.
If we are developing an RCS app to replace SMS. Is it possible to deal
with receiving SMS directly?
It depends what you intend to do. You won't be able to fundamentally change the SMS protocol on the telephony network as this is not within your control as an application. However, you can create an app to monitor and listen for SMS message as they are received in the OS. You can check out this post on how to do that. If you wanted to create your own RCS, you'd pretty much have to do this over the Internet. Services like WhatsApp have made clever use of combining both telephony SMS and standard Internet messaging to create a seemingly seamless experience. Without further context on what you're trying to build, I won't be able to provide more help.
In the end, you should just think of native SMS as being part of the phone. For further readings on how SMS works, I suggest the SMS Wikipedia page. I hope I was able to answer some of your questions!

Handling notifications in 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.

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.

sending notification between Android devices

I have App "A" in android device "A" and i have the App "A" in android device "B" . Is it possible for me to send the notifications between the devices through WIFI??
Thanks in advance
There's a variety of ways to do this, but ultimately it all boils down to have an app running on the second device that receives some trigger to show a notification.
Some examples....
You can have an app with a open server socket on device b and then discover and connect to it to send a message that triggers a notification over TCP/IP. http://jmdns.sourceforge.net/ can help with discovery.
If they both have a network connection, you can build something on the App Engine to send a C2DM message to device B, and then upon receiving that message trigger a notification.

Categories

Resources