4

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

Bora
  • 1,933
  • 3
  • 28
  • 54
  • 1
    Google "firebase app engine" and the first hint points to [this tutorial](https://cloud.google.com/solutions/mobile/firebase-app-engine-android-studio) in cloud.google.com. It uses Firebase + App Engine to send email notifications. So swap out the email code for your GCM code and you're good to go. – Frank van Puffelen Feb 16 '16 at 20:20
  • @FrankvanPuffelen Yes i saw that, however it makes me to use cron.xml for keep listening for data changes in Firebase, i guess its not good. – Bora Feb 17 '16 at 17:53
  • That tutorial was written by an engineer who worked on both app engine and Firebase. I'd take his opinion over my own guesses any day. – Frank van Puffelen Feb 17 '16 at 22:29
  • As of today (May 19 2016) Google just rebranded GCM to Firebase Cloud Messaging and it now offers [this](https://firebase.google.com/docs/cloud-messaging/) as a cross platform service. It also offers [notifications](https://firebase.google.com/docs/notifications/). See [this](http://stackoverflow.com/a/37336674/3032209) response for a complete answer. – Yair Kukielka May 20 '16 at 01:48
  • 1
    Now you can send push notification to all or specific devices/users using your app server and firebase. for working example visit this blog post. http://codingaffairs.blogspot.com/2016/06/firebase-cloud-messaging-push.html – Developine Jun 20 '16 at 08:09
  • @Hammad Thanks let me go through it – Bora Jun 20 '16 at 08:12
  • @Bora please upvote my answer at the end. if link helped you. thanks – Developine Jun 20 '16 at 08:17

1 Answers1

1

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.

Tom
  • 17,103
  • 8
  • 67
  • 75
  • Thanks Tom. You said to use any regular compute engine, do you have any in mind that woks good with Firebase – Bora Feb 17 '16 at 17:54
  • I think one of google's goals with Firebase is to make it work well with any language/platform, but probably easiest to use compute engine, and since you tagged this with 'android', probably makes sense for you to stick to Java. – Tom Feb 17 '16 at 18:20