Server authenticates against google client login to use app engine's C2DM server. I understand that. I will use .net here. When data changes, I will send push notification to client and client service will refresh the data in their device db and UI will be updated. I am expecting this way the whole thing will work
All clients needs to register to server for receiving C2DM calls. Here there are interesting scenarios.
In my app there is a login in order to manage authentication and authorization to filter out the data that is relevant to him only. so at the same time I have to register to C2DM server as well. Is that correct?
Let's take an example of task which is assigned to some user. If the
task is updated by user, it show send C2DM message to it's owner, and
it owner creates task it should send C2DM message to user who is
responsible for the task.
Is this practically possible? Is anything that I am missing or understanding wrong?
Yes this is practically possible, but remember
you can send only limited data in your payload.
you have to write all logics inside your app to change UI.
Payload message data can only pin the decision making process.
Related
My Android client app does not receive any Firebase push notifications targeting topics, however I immediately receive notifications sent to all app users or notifications sent to specific devices.
I didn't change anything in my code and I checked whether the client is correctly subscribed to topics.
For further details about my subscription logic:
In order to make it easy for my web service to send notifications to a specific user, each user is subscribed to a topic entitled with his user-id whenever he logs in from the client app.
Is this approach weak somehow? Should I otherwise register the device token to my database every time it's updated? And then send the notification to that specific token?
Should I otherwise register the device token to my database every time it's updated? And then send the notification to that specific token?
It is highly suggested that developers save the generated registration token for each device for later use. As mentioned in the docs:
After you've obtained the token, you can send it to your app server and store it using your preferred method.
In your case, it is preferable. It'll remove the added action of subscribing the device to a topic. Plus it can be useful to track the message status using Diagnostics tool should you need it in the future.
I'm building an app that allows the user to create events and add people to those events. It stores the event and certain user data (email and display name) in a Firebase database.
What I'm trying to do is send a notification to a specific user when another user adds them to an event. I've tried looking at the documentation for both Firebase Notifications/Cloud Messaging and Batch, but I can't find a way to send the notification to a single user, rather than an entire group.
How do I go about doing this? I'm hoping to avoid storing the notification in the Firebase DB and setting up a servlet backend that queries the DB repeatedly.
Edit: If I do have to make a Java Servlet backend for this, can someone tell me how I would code it?
I think you can do that by specifying the device token when sending the notification using console or using post request to FCM server. But unfortunately you have to handle every single device token manually by yourself (get it from the device when it register to FCM, and save it to your own DB somewhere).
If you use console, you can put the token on "FCM registration token" field under target -> single device.
If you use post request, you can make a request like this
{
"data": {"my_custom_key" : "my_custom_value"},
"registration_ids": ["your-device-token","your-device2-token"]
}
Batch.com provides a simpler API named Transactional API to send a notification to one or more users identified by their User ID, Firebase UID etc. as you probably don't want to deal with the complexity of APNS push tokens or GCM registration ids yourself. Contrary to FCM, you will get a complete analytics view (eg: open-rate) on those notifications.
You can trigger push notifications directly from your app code by using our Swift client for the Transactional API or by coding your own HTTP client (it's a standard POST request with a JSON body). We even have a client for Node.js if you decide to trigger the notifications from a server.
And if you are using Firebase, we have a specific documentation to plug Firebase with Batch.
I'm totally new to hybrid world so I have to ask first.
Can I send notifications through GCM without a server?
I mean, I'm building a SPA with AngularJS and Firebase, but my customer asked me to make a dashboard for Android, so every time an user makes an order, they (both dashboard administrators) receive a PUSH notification on their phone: "A new order has been created", and when they "tap", the application opens.
I've been reading something about /topic/ endpoint to notify both of them, but I think I still need a server to do it. Do I?
It would be great if I simply post a http query using something like AngularJS' $http service to tell GCM to send a notification for that topic/usergroup.
Is that possible? If so, any idea about how?
Thank you very much in advance!
Sending a downstream GCM message can be done "without a server". One option is to send an HTTP request to GCM containing the required fields. Topic Messaging is available with GCM which does make it easier to send downstream messages without a server. Your client apps can subscribe for messages from /topic/usergroup and then you can send an HTTP request with /topic/usergroup as your "to" value, and subscribed clients will get it.
Note that you will need to set up a Google Developer Console project to get the required API key.
Check here for more information on the structure of GCM HTTP downstream messages.
I have an android app which i connect to my server using REST API (django rest framework)
here is a scenario(and maybe my plan):
data is sent back and forth as json
I have a user model and a task model where users are owners of some task.
Users typicaly sends a task to another user (with json similar to this: {"owner": "exampleuser", "from":"otheruser", "content":"example" ...} using POST method)
-The tasks has a boolean field "completed" and is deleted once the task is completed (using PUT or PATCH method: completed = true,)
once a new task gets created using POST method, the only way users can see any activities concerning their tasks is through an android activity that uses GET method to get a list of all the tasks owned by the user, by looking up all objects owned by the user
So my questions are:
Instead of having the user to check the app everytime. How can I use GCM to push notify the user?
How will it tell which user or device to send the push notification to?
How does GCM knows when there has been a change to tasks or when a user POST a task?
Android keeps one active connection to Google's servers, but it doesn't use much power or data, because no traffic is sent along it until something sends a GCM message to an app on your phone. There's only one connection on the phone, used by all apps: installing a new app that uses GCM doesn't add any extra load.
The first step in GCM is that a third-party server (such as an email server) sends a request to Google's GCM server. This server then sends the message to your device, through that open connection. The Android system looks at the message to determine which app it's for, and starts that app. The app must have registered with Android to use GCM, and it must have the relevant permission. When the app starts, it might create a notification straight away with the data from the message. GCM messages are very limited in size, so the app might instead open a normal connection to the third-party server to get more information (for example, downloading the headers of new emails).
The advantage of using push notifications is that apps don't have to run at regular intervals to check for new data, saving both power and data. The advantage of having a centralized mechanism like GCM is that the device only needs one open network connection and the Android GCM system is the only thing that needs to keep running, rather than each app having to stay running in the background to keep its own network connection to its own server.
As per the GCM implementation, it requires that you implement a remote server which will manage all the requests, both incoming and outgoing. You can do this simply with a web server acting as a webservice, which will get (for instance) the requests from the clients with a HTTP POST request, and process act consequently.
Instead of having the user to check the app everytime. How can I use GCM to push notify the user?
This will be managed by the server that I just described. It will know who is subscribed and who should receive the notifications.
How will it tell which user or device to send the push notification to?
Same goes here. The server, upon a subscription, should store the users in some kind of storage (a SQL database, for instance), and this way it will know who to send notifications. This implies you'll have to implement some timeout mechanism. In my case, I make clients send a dummy HTTP POST every 30 seconds. If I don't get this request from a reasonable amount of time, I consider the client timed-out and therefore I remove them from the database.
How does GCM knows when there has been a change to tasks or when a user POST a task?
Same story, it's all handled by the server. You implement the logic of what should happen upon any request.
You might want to read this: How to send location of the device on server when needed
And also this references:
Reference on Google Cloud Messaging
Android Push Notifications using Google Cloud Messaging GCM - Android Example
Google Cloud Messaging using PHP
Connection between PHP (server) and Android (client) Using HTTP and JSON
Notificaciones Push Android: Google Cloud Messaging (GCM). ImplementaciĆ³n Cliente (Nueva VersiĆ³n) (spanish)
Our organization has an Android app and an iOS app.
We want to start pushing notification to these apps.
Android has GCM.
Apple has APNS.
But we want to create an API which will work on both android and iOS.
What is the easiest way to setup a server so that when a push notification needs to be sent, it knows exactly which server to send the message to?
I use a service called Parse to do my notification pushes to both Android and iOS. They have great documentation and libraries available. You can get some details here: https://parse.com/products/push
As a little background this is for a university setting where multiple colleges apps as well as distance education may be using the service. Here is the approach that we are using in our organization. If you look at the way APNS works it can be used by just sending a web call to the APNS service with the token id. GCM is very close to the same type of system. Basically create a JSON package and send it to the desired service.
Here is our steps we used to create this service.
Server admins created a server and database that can be called that will collect the tokens from both android and ios devices. When the device registers we also send what type of device it is. This is possible since we are just sending data to the database that is has been created.
From here we then created a couple of python scripts that send the data do the desired service whether it is ios or android. These scripts gather the appropriate data from the database and sends the packaged data (JSON package) to APNS for ios message and GCM for google cloud.
We also created a web interface so that those who need to send messages to the devices can.
The rest of the implementation is up to you to decide the best way to utilize the service. For example when to check for invalid devices,
Because we are planning on using this same server for multiple applications we can send the type of device, token, application, or whatever else is needed for an application to distinguish it from others we produce so that each application that wants to use the service can. I hope this helps and gives you some idea on how to accomplish this.
For APNS, Maybe you may consider this forked version of PyAPNS that has enhanced message support.
https://github.com/jimhorng/PyAPNs
which means it will catch error response for failure messages and resent the message which are discarded by APNS while sending between failure messages and receiving error response.
Solution:
Non-blocking ssl socket connection to send notification without waiting for response.
A separate thread for constantly checking error-response from read connection.
A sent notification buffer used for re-sending notification that were sent after failed notification, or arbitrary connection close by apns.
(Reference to non-blocking apns pull request by minorblend, enhanced message by hagino3000)
Result:
Send notification at throughput of 1000/secs
In worse case of when 1st notification sent failed, error-response respond after 1 secs and 999 notification sent are discarded by APNS at the mean time, all discarded 999 notifications will be resent without loosing any of them. With the same logic, if notification resent failed, it will resent rest of resent notification after the failed one.
For GCM, you may consider https://github.com/geeknam/python-gcm
For generic wrapper that support both or more mobile provider:
https://github.com/Redth/PushSharp