I want to know if it is possible in google cloud messaging api to send messages directly from one android device to another without relying on our app server. I don't have a server so is it possible to send messages device to device through gcm?
GCM supports device to device messaging. However, your devices would need to somehow know registration ids of each other, which is hardly achievable without coordination from your own server.
Currently sending a device to device message is not possible with GCM, even if the two devices have exchanged InstanceId tokens.
Related
I am trying to figure out how Firebase connect to specific devices and send message to it. I now how to use Firebase and send notification to registed devices from my backend server but i don't know how is it working internally. Is firebase severs using persisted connection between device and server? What kind of tehnology is it using?
For now i am mostly interested in Android devices and how firebase wake up device even with background tasks restrictions.
FCM is able to wake a device because the message is actually received by software components that come with Play services, which operates with elevated privileges. Play services can choose to wake the device and deliver the message to the target app.
The FCM software in Play services keeps a persistent socket connection open to its backend under normal circumstances. If it gets connection is dropped, it has logic to reestablish the connection without taxing the battery too much.
I tried to explain how GCM works in my answer here. The internal working principle of Firebase is similar in my opinion.
When you are installing an application which has the Firebase SDK set up in it, it gets a push registration ID from Google server. Usually, you save the push registration ID in your server as well. Hence, when there is a situation for sending a push notification, your server uses this push registration ID to generate a request to the Firebase server for sending a push notification to your device.
Now let us think of the receiver part as well (i.e. your device). In my opinion, in newer versions of Android allows a JobScheduler to check repeatedly for push messages from the Firebase server and if there is one, the device notifies the corresponding application and the application then generates the push notification.
Hope that helps!
can someone explain about how push notification or message in android working? Does it operate within a VPN? How can the server send data to the device if it's not in the same network? Is it possible to make your own push notification/message? Please enlightened me :)
Push Notification in Android means, Google Cloud Messaging. First we need to enable google cloud messaging service from google developer console. Then need to create browser key to give from server side.
Now, when user need push, we have to register the device id to the google cloud server and it saved it permanently.
Now when server fires push at that time server request google cloud to send message to registered device id, and using that device id, google sends message to that particular device. So basically, whole things are depends on Device id.
I read about Google Cloud Messaging at http://developer.android.com/google/gcm/gcm.html.
It supports Third Party Application server to Android application push notification.
I am wondering whether it is possible to implement the same thing push/receive notification from an Android app on one mobile to the same Android app on another mobile using Google Cloud Messaging.
If not, is there any other free service available similar to Google Cloud Messaging?
An Android device can send a GCM message to another Android device. All it needs is the API Key (of the Google API Project ID that the app uses to register to GCM) an the Registration ID of the other device. Using these parameters it can send a GCM message to another device via an HTTP request.
Usually applications that use GCM require a 3rd party server in order to store the Registration IDs of all registered devices. If your app has a different way to let devices share their Registration IDs with each other without requiring a server, you don't need the server.
As far as I'm aware, there has to be a server in the middle to send the push notifications (Android -> Personal Server -> GCM Server -> Android)
So the Android device sending the notification would send some data to a script on the server (using a HTTP GET/POST), and that script would then send the push notifications to all the devices that you wanted it to
Following the example Code from google (GCM Client Example), you can build an app to get a registration ID for your device, but sending messages without a server wouldn't work in my opinion. I didn't tried by now, but what about using the Google Backend Starter, or (what I tried) using a Backend as a Service Provider like apiOmat if you can't afford or don't want to set up a server.
I'm trying to use GCM to establish communication between some users. They should send to each other their GPS location. Is it even possible? There is a subscribeToCloudMessage method but I don't know whether it will be useful or not.
Info: Server works fine (Google app-engine) with all the required keys.
It's possible for one app to send a message to another app via Google Cloud Messaging if the sending app knows the registration ID of the recipient app. Usually when a app register to Google Cloud Messaging, it sends it's Registration ID to a server, and that server sends GCM notifications. If you want the app to send the notifications directly, you must send each device (where the app is installed) the Registration IDs of other devices that it needs to send messages to.
Is it true that if a user does not have Cloud to Device Messaging (C2DM) in his account the C2DM will not work?
If so, how can I do push notifications without a Google account?
The different techniques to send push notifications can be listed as follows
Android Cloud to Device Messaging (C2DM) on OS2.2+
Other techniques for pre OS2.2 Devices.
Cloud to Device Messaging (C2DM) OS2.2+: The standard push notification method used in the android platform is called Android Cloud to Device Messaging (C2DM). The service provides a simple, lightweight mechanism that a server can use to tell an app to contact the server directly, to fetch updated data.
C2DM allows to send lightweight messages to android apps. The messaging service is not designed for sending a lot of user content via the messages. Rather, it should be used to tell the apps that there is new alert on the server, so that the application can fetch it.
C2DM limitations:
The message size limit is 1024 bytes.
Google limits the number of messages a sender sends in aggregate, and the number of messages a sender sends to a specific device
C2DM makes no guarantees about delivery or the order of messages
C2DM requires users to set up their Google account on their mobile devices.
C2DM requires devices running Android 2.2 or higher that also have the Market application installed
Server should be
Able to use HTTPS to communicate with C2DM Server.
Able to communicate with our client.
Able to fire off HTTP requests to the C2DM server.
Able to handle requests and queue data as needed. For example, it should be able to perform exponential back off.
Able to store the ClientLogin Auth token and client registration IDs. The ClientLogin Auth token is included in the header of POST requests that send messages. For more discussion of this topic, see ClientLogin for Installed Applications. The server should store the token and have a policy to refresh it periodically.
Other techniques for pre OS2.2 Devices:
Poll rather than push
SMS
Persistent TCP/IP
Third-party offerings
Poll rather than push: Android app can periodically poll the server for new messages from a background local service. The more often you poll the closer you get to the real-time push.
Adv: Easy to implement.
Disadv: Not real-time.Will kill the battery.
SMS: Android apps can intercept text messages in the android phone.So if a server can send an sms when there is a notification, the android app can receive the sms and then check for new data at server.
Adv: easy to implement. Fully real-time updates.
Disadv: Can be costly to do.
Ericsson labs provide a hosted service which allows upto 2000Sms's to be sent.
Persistent TCP/IP: The android app initiates a long-lived mostly idle TCP/IP connection with the server and maintains it by occasionally sending keepalive messages. Whenever there is something new on the server, it sends a messages to the phone over the TCP connection.
Adv: Fully real-time updates.
Disadv: Hard to implement a reliable service on both the phone and the server side. The Android OS is known to be able to kill services when it’s running low on memory, so our notifications service can easily disappear. What happens when our phone goes to sleep? Imagine if all the apps use the same technique . there will be plenty of open connetions which will drain the battery.
Third-party offerings
Urban Airship Push : The big disadvantage is that it requires the user install the AirMail app onto their device.
The deacon project
xtify
pushdroid.org