Push Notification using Firebase and Google Cloud Messaging - android

I want to send push notification in my app (Android) using Google Cloud Messaging. I am using firebase for backend. As firebase do not support inbuilt push notification i am using Google App Engine.
I do not have any idea on Google App Engine. Right now i am using a template provided by google for sending push notification.
Google Cloud Messaging Template Github
Till now i have deployed my app in Google App Engine and i am able to send push notification to all devices that are registered (From Web) An HTML page i get when i use GCM template.
What i want to do is , to Listen for Firebase data change and send push notification to user who is not online or has closed the app.
How can i run a servlet in background so that it keeps running in background and send push to user who is not online/connected.
As i have only push notification logic in Google App Engine Should i use servlet or struts.
Thanks in Advance

It is my understanding that Firebase really doesn't work very well with GAE, so you might want to reconsider your choices.
Listening for data changes, as you have mentioned, requires that your app leave a background thread running. To do this on GAE you have to disable automatic scaling which is an important feature of GAE.
You could create a separate backend GAE module with manual scaling and then have it use eg. a queue to notify your main GAE module of a data change, but this seems to me to be unnecessarily complicated and inefficient.
Hopefully Firebase will improve their product so it can notify of data changes in a more efficient and flexible manner, but in the mean-time, perhaps you should use a regular compute engine instance.

Related

Push Notification from local server

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.

How can I automate sending push notification when an event occurs in back-end of android app provided I'm using Firebase as Backend

Consider a whatsapp group. When any user texts in group, all the participants receive a notification.
Consider Youtube, whenever a content creator uploads a video, I get notifications.
These are all automated.
How to do this? I use Firebase as backend in my android app.
You need back-end services that you communicate with through an Api from your app. Think of this as a communication layer between Firebase and your app.
Generally this can be considered as a REST API. Here is more reading:
https://restfulapi.net/rest-api-design-tutorial-with-example/

Android push notification without firebase

I want to send android push notification to the selected user without using gcm or firebase. The application is already built without firebase. Now I need to integrate push notification too.
Question:
How it's possible without firebase?
Actually I want a feature that, when an admin update the value in the one field in database table of particular user, the that user will get a push notification regarding the update. How it is possible?
The way is to create custom Service https://developer.android.com/reference/android/app/Service.html , which is holding connection via socket or polling some remote server with intervals.
But, I suggest that Firebase service is more advanced and optimized in battery consumption and, particularly, in utilizing the sleep mode. It's not trivial to make a service which will have fast response and CPU consumption. I think that a custom service development will lead to native (C++) coding of networking routines libs.
Also, take into account that Firebase provides own Authentication service with ability to seamless convert your anonymous user to registered. There is a lot of pros of Firebase services. And cons are: your users have to install Google Play Services, if your app will grow - you will pay to Firebase.
Look here Android push notification without Google service
It's possible using VAPID authentication.
Google for VAPID and you will find a very tortuous road that could lead to the answer you are looking for.
another option is Gotify. Gotify is self-hosted open source notification solution that you can use it to send push notification to your android app without need of Firebase.
with help of UnifiedPush you can receive push notifications in your android app.
you can easily host Gotify server on Docker and use it's Api or cli,... to send notifications.
here is a good article about Gotify: https://www.linux-magazine.com/Issues/2020/230/Gotify

Push Notifications in Android using Google App Engine

I am currently developing an app where users create posts that are stored on a server. When another user shows interest in a post by clicking a button, I want to notify the author of the post using push notifications. I have already set up the data storage using cloud endpoints with Google App Engine. Is there anyway I can use these endpoints to implement push notifications? If not is there another easy way to implement push notifications given my current setup? I have already read about Google Cloud Messaging on the developers page but was somewhat confused. I have kept track of the registration id's but I don't really know where to go from there. Thanks in advance.
You can use the HTTP interface to the GCM servers as described in this
Android developers page.
The easiest way to do it is by downloading the Google Cloud Messaging for Android Library using the Android SDK Manager, which will give you a jar that handles all the complexity of setting up the requests and responses to GCM.
Towards the bottom of that page, there is a sample Java application for push notifications on App Engine which you can use to get familiar with sending push notifications and then adapt to your needs.

Instant Messaging on Android with Google Cloud Messaging

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.

Categories

Resources