What is the recommended way to send updates from a server to an Android app? I need to send data from the server that will show up in the Android notification list.
Polling the server is one option. But is there a better way? I have a website that receives updates from the same server using HTML5 Server Sent Events. Is there a way of doing something like this in an Android app, ie. creating a persistent connection that listens for server events?
Anyone know the best practise way of implementing this functionality in an Android app?
Have a look at Google Cloud Messaging, this is a free service for android phones that allows server pushing. It allows you to push messages , notifications or data.
Its very hard to say if theres a best practice , it all depends what you are doing. But If you follow the example in the guide , it should be fine.
Related
I am building my first Android app and need to know how I could use push notification.
My project is a home alarm system and also I have built my own local web server. Now I want to push a notification from my server to my Android app when an alarm appears in my server.
Currently my garage doors use the MyQ app and when the garage door opens or closes I get a notification on my phone, I want to implement the same thing in my app.
I've been reading about the Google Firebase Cloud Messaging but it seems exceeding my need.
If you need push notification on your cell phone then you definitely need to integrate your app with Google Firebase. (or at least that's the right way of doing it).
Alternatively, there is something called as local notifications & background process in Android you could do long polling to check if the garage door is open (probably every 2 mins or something). However, I don't recommend that as it can drain your mobile battery.
Also I recommend using Flutter as oppose to using Native Android. As there are some pre-built libraries for android and Google Firebase integration.
Take a look at this Youtube video - https://www.youtube.com/watch?v=2TSm2YGBT1s
Ouh, maybe thats a little bit too much for starting with android - nevertheless I want to help you.
You need a communication protocol between your server and your phone (i.e. Firebase as you mentioned or Websockets).
If your server sends a message to you client (your phone) you have to create a notification. (Android Developer Guide). That's the theoretical part. You will also stumble across a lot of
challenges with
asynchronous programming.
Firebase might actually be the simplest option. You could build your own web socket service too, but that would probably be more than you need. See this previous question for more options: Android push notification without firebase
Android has some services that communicate with firebase to receive notifications.
You'll need to implement a service on top of your web server (using backend languages such as Python, Node.js, PHP,...) so it can send notifications when an event happened (like the door closed) witch isn't a simple way for a beginner.
then your web server sends a message to firebase and tells it to send a notification to my client.
so I highly recommend using firebase because of the simplicity of usage. otherwise, you should implement a separate service on your android phone to get the notification (if you want to run it locally) also as explained do the backend side.
I'm new to Android and want some advice please.
I need to build two Android applications.
Android application for train travelers
Purpose: Sending a custom message (for assistence) to the railway guard. The railway guard will be identified on the basis of the wagon number that has been sent.
Android application for train guards.
Guard must be able to login and be able to receive (realtime) messages from travelers.
In short, this should be a one-way messaging system.
I'm used to build RESTful web application with databases. I have no idea which technologies i should use in this situation. As far i know i can't use databases such as MySQL, Oracle on Android. I've read that Firebase is an alternative for this but i'm not sure if it's the ideal solution for this kind of application.
I could build a RESTful server and make calls from the application. I guess if i do so the messages won't be received as realtime push notifications.
Any advice please?
RESTful services are hosted on a server and cater to incoming requests with a response.
Remote notifications are handled by a remote server. Under this
scenario, the client application needs to be registered on the server
with a unique key (e.g., a UUID). The server then fires the message
against the unique key to deliver the message to the client
application via an agreed client/server protocol such as HTTP or XMPP
and the client displays the message received. When the push
notification arrives, it can transmit short notifications and
messages, set badges on application icons or play alert sounds to
attract user's attention.[21] Push notifications are usually used by
applications to bring information to users' attention.
Source of above text
You can understand the basics and implement it into your application.
However, it is too much work and you really won't be gaining much.
It is much better to use Firebase and the documentation is quite good.
You need to pay as you go based on how much you are using Firebase.
A place to start:
https://firebase.google.com/docs/cloud-messaging/
I'm making a NodeJS server and an Android app that goes with it. I need to send alerts to my mobile app users that's coming from the web server. Something like a a chat app on the server and the android users getting the messages also (Facebook messenger?).
I have the server ready and Android app communicating to its database (for user login/getting user info/etc) using REST. I just need to figure out how to send info to the Android app WITH THE SERVER INITIATING COMMUNICATION. Any advice on where to start?
Start by looking at Google Cloud Messaging.
It's a free service that accepts messages from your server-based program and queues it to be sent to phones with your app when the phones are online.
Here is the overview on Android Developers.
YES!
Working with NodeJS, you have probably already heard of Socket.IO.
I'd say: Start there!
For your app to communicate with the server, there's also the java lib. These are great tools to start making any good real time service.
After you get along with this, you should also check GCM as #krisLarson suggested. And talkign about GCM, you have Node-GCM to make your work even easier.
Good luck!
I am developing an app in android in Eclipse IDE. The app modality requires that any user can challenge his/her friend to do a certain activity. Whenever a user does so, the friend will immediately get a notification in his/her phone. Even more, the user who challenged the friend, will also receive a notification when the friend accepts the challenge. Is there any particular way I can provide this functionality? I know how to generate notifications. But the server side interaction is quite confusing. Should I check the server database through the app at frequent intervals and check for such activities in database? I think the procedure will hamper the performance of the app. I would be very grateful if anyone can suggest a good way.
But the server side interaction is quite confusing.
As you're pointing out, it's the server part not the Android one what's confusing here. If you don't have any constraints on the server part, I'd recomend to use Socket.io http://socket.io/ They have a tutorial for connecting socket.io with Android: http://socket.io/blog/native-socket-io-and-android/
It seems that you don't really need an interaction between the differents users but only a way to notify them. I always used Google Cloud Messaging to do so. It enables you to receive push notifications. As you said, checking the server periodically is battery/data consuming and not the best way to do it.
This link might help to set up GCM : http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/.
I want to know the complete working mechanism of the mail apps for android.
Actually I build an android app for big data product.It has a feature which will shows the notifications (list view) .
Now I want If new notifications come in the DB It should ring a bell and in notification bar of the android phone it should show, As in case of Mail apps, as soon as we got new mail a notification comes in notification bar.
NOTE: android server which needs to be queried may not contain internet.This App works on intranet also.within a company network.(without the internet)
So I want to know the mechanism to implement this feature.
1) Whether i should run a background service which will send query to server on regular time interval.
2) Or any other services like push notification.
I just need a clear idea about working of these type of system.So that I can implement this in effective manner.
Thanks
Obviously the best solutions would be to use PushNotifications. This is how GMail does it, and this is how every email app, or messaging app has to do it.
Polling the server will drain the battery, and will also make extra (unnecessary) data traffic, which is something you don't want your app to do .
You should get started here : Google Cloud Messaging. In my opinion it is very easy to setup, and I recommend using GCM, instead of all the other alternatives like Parse and so on.