I am currently developing an Android app and I would like to include Firebase Cloud Messaging.
I was planning to have a Raspberry Pi checking a website every 5 Minutes or so and sending push notifications when something changed.
In the official documentation they say that I need an 'app-server' in order to send messages via Firebase.
Does that mean I need to have my Raspi up and running as a server 24/7 and need a static IP / Domain for it?
Or is it enough to have my Raspi send the message via the Api (https://fcm.googleapis.com/fcm/send) as I only need downstream messages?
Any help and explanation would be highly appreciated as I can't find a definite answer in any thread or documentation.
You don't as such need an app-server for just one device. If you have some sort of internet connectivity on your Raspberry Pi device, all you need to do is make a request to the firebase API.
Firebase (Google servers) will handle the rest by pushing notifications to all the registered devices.
Sending downstream messages (messages to devices) requires that you specify the FCM server key. This key allows sending FCM messages on your behalf, so should only be used on environments you trust.
Typically this means a server that you control. But the recently launched Cloud Functions for Firebase can also serve as such a trusted environment. After all: only developers who have access to your Firebase project can access your Cloud Functions code, and those developers can already send messages using the Notification panel in the Firebase console.
Any device you control in your own environment is also fine as a trusted environment. It doesn't have to have a fixed IP address, since the FCM server typically receives its instructions through XMPP or (more commonly these days) through the Firebase Database. Both of these approaches initiate the connections from the trusted device to Google's servers, so can run without accepting incoming connections.
You don't need any server to implement FCM.
Related
I have raspberry pi and an android app. I want to send notifications from the pi to my smartphone app. Is this possible?
The notification needs to be on a individual user basis
Firebase and Google Cloud Messaging seem to be an option.
The pi will act as a server and the android app a client.
The android app does not sent information back.
Again, is the above possible using either Firebase or Google Cloud Messaging.
It actually is possible, you need to setup the server and use the Firebase Admin SDK, see here. You could have a Python server (for example Django), Node.js, Java or Go server. You can have any of these in the Pi.
With the admin SDK you need only to configure it to have the same project ID as the app, then you can send notifications with the SDK, see here.
Note that you'll probably need to save the FCM tokens from the clients in the real time database so you can access them through the Admin SDK and simply direct the messages to them. Or you could have your clients subscribe to a topic and send the notification to the topic, which is much easier than needing to manage tokens.
I am doing a prototype that involves messaging between clients.
What I want to do - from MyApp on device1, able to send message to MyApp on device2. Device2 should receive this and show a notification.
I don't have my own application server to push notifications from GCM to GCM clients.Is this possible ? How to do it ?
What I investigated - PubNub, which has a trial license that seems to answer my need to send messages on a channel without needing a server.
This discussion at SO didn't help much.
sending client to client messages without server interaction
Can anyone suggest better ways ?
You basically have to use a server in one way or another. I think Firebase would be perfect for your purposes. It has an Android plugin you can use that will basically alert your app when something changes in the database. Here is the documentation for that feature. Take a look at this example for implementation. Before you can use the plugin, you need to create an account and whatnot (basic one is free). Here are the instructions.
PubNub Realtime Messaging and Push Notifications
(server not required)
With PubNub, you do not need your own server to do the realtime messaging or the mobile push notifications. You likely have your own server for your database (MySQL or similar, traditional RDBMS, a No SQL DB like MongoDB, or a realtime DB sync, like Firebase) to authenticate users and such.
For realtime DB or non-DB type change notifications and signaling (any type of realtime messaging), PubNub makes is super simple to receive messages in realtime with a mobile push notification fallback in one publish action. So the GCM message will be sent along with the realtime message. If the app is actively running, you get it in realtime (< 1/4 on average - typically faster) and the GCM message will be received if the app is not active (background or not started at all).
And PubNub's free plan is not a trial (anymore). It is free (including all add-ons) for as long as you stay within the free plan limits.
See the PubNub Android docs for more details and contact PubNub support if you have any further questions with getting started or getting answers to any questions you have as you progress with your app implementation.
Another possibility is to use the SMS.
Android Send and Recieve Messages
"Send Binary (Data) SMS
We can send binary messages (as opposed to text based messages that we covered earlier) to specific application ports using sendDataMessage(). According to this Stack Exchange thread data sms is one which is sent over 2G/3G as well as GSM. I’ve tested it with mobile data turned off and it works fine charging me the same amount, so not very sure on whether it uses 2G/3G or not, but generally the term data is used in telephony when it’s related to network (tcp/ip). Anyway, SMS’s are generally sent to a specific port on the device (which is probably port 0 [zero]). But using sendDataMessage() we can send SMS’s to some other random port on which our app can listen for incoming SMSs and do something with that. In this case the default messaging app will not store the SMSs in their inbox for both the sender as well as the receiver.
"
stackoverflow fellows,
Since I am very new in Cloud Computing matters, I would like to ask you a question: Google Cloud Messaging for Android works from server to client, but also viceversa(from client to server)?
I am asking you this, because I am currently developing an Android application. The structure, in general lines, it's something like: I would like to use my laptop as a server - and perform all the computations here. Then, from my server (laptop), to send everything in the cloud, and from the cloud, directly to my Android running device. I want to perform the computing and database storage on my local server (because, since I am a student, I won't have enough money to actually pay for a server from google (let's say), so I am focusing on what's free and suitable to my needs) and just communicate with my Android device using Google Cloud Messaging for Android. (I want my application to be independent from the hardware of my mobile device, and also, I want to write the program that will perform the computations on my server in Java).
I know that I can send messages from the server to my device(through cloud), but the question is: can I also send messages from my device to the server ? I am asking this, because the computations will be made after I submit something from my device (basically, my Android application will be an interface, from where I can send the data to my server (through cloud) and then receive (also through cloud) the results of the computation on my device)
According to what I've been currently reading (http://developer.android.com/google/gcm/index.html) it seems that I can only send messages from the server to my device, but I decided to ask, since, so far, was the only free messaging framework(using cloud) I have found.
Thank you.
You can use GCM Cloud Connection Server to send messages from device to server.
Paragraph from this page:
http://developer.android.com/google/gcm/ccs.html
The GCM Cloud Connection Server (CCS) allows third party servers to communicate with Android devices by establishing a persistent TCP connection with Google servers using the XMPP protocol. This communication is asynchronous and bidirectional.
Google Cloud Messaging for Android works from server to client, but
also viceversa(from client to server)?
Sorry but GCM(Google Cloud Messaging) is only made up for sending Push Notification from server to device. Not for Viceversa.
I know that I can send messages from the server to my device(through
cloud), but the question is: can I also send messages from my device
to the server ?
For sending the message or anything(For Example: Photo,files..) to Server why Don't you Use Web services for it. I think it will Be suitable according to your Needs.
It is correct what KashifB wrote:
You can use GCM Cloud Connection Server to send messages from device
to server.
But keep in mind that Messages with Payload have a size limit of 4kb per message.
I was just looking at the new Google Cloud Messaging (GCM) and I was wondering if it is possible to use GCM for Instant Messaging on your Android application?
I saw you can send data, like a message, from a server, but is it also possible to send from one device to another one?
And how would this work?
Some example code would be really helpful..
Tnx!
The official docs on Google Cloud Messaging for Android does mention that GCM can be used to develop an instant messaging app.
...or it could be a message containing up to 4kb of payload data (so
apps like instant messaging can consume the message directly).
So we went ahead and created an instant messaging app using GCM. The server-side is powered by Google App Engine. You can read the complete tutorial here. Create an Instant Messaging app using Google Cloud Messaging (GCM)
So it is possible to use GCM for Instant Messaging on Android, to answer your question. However, reliability of GCM compared to XMPP for IM is another topic.
Just my two cents:
I think you should not use GCM for delivering IM. You should have a dedicated server where your Android IM apps will connect to, using a persistent socket connection. Your server will know who is online or not and therefore can present an 'online list' to all the apps.
GCM can come into play, while users are offline or not running your app. A GCM message can be sent to them to indicate 'XXXX wants to chat'. They can then launch your app and automatically connects to a chat session.
Google has said that the delivery of GCM messages are not guaranteed. This reason alone is not a good idea to rely on them for Instant Messaging.
Try pub nub - it is pretty easy to implement - send Im from one mobile to another - simply fire up the web page (see link) in the browser , and chat between pc, mobile - and works - with 'no server'. Code is for javascript but they also have java. Chat app using jquerymobile web app framework
You might want to check out how a server sends a message to the GCM Service. It is possible to use php on Server side so it should be possible to adapt that to a POST request directly out of your application. However, to communicate you need the registered ids of the devices you want to send data to. Means you will need something to store and get them. Best solution would be your own (web) server which stores all ids and handles the Message sending.
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