Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm working for the first time on a game for Android using Unity and I need to use Google Cloud Messaging to receive push messages.

I've already done the integration of my Unity project with GCM, using this project, and of now I can receive and read messages sent to my phone while the game is running. However, I want to be able to receive them while the app is closed. Currently, if I send a message and the app is not running, I get an error stating that my app stopped working.

So, in essence, I want to know: what are the steps to handle incoming push messages when my app is closed, display them as a notification in Android and launch my game app when I open such notification? What else should I do outside Unity so my project can handle Android notifications while closed?

share|improve this question
up vote 0 down vote accepted

I'm not sure what your problem is. If you have successfully integrated GCM messaging, then it wouldn't matter if your app is running or not, as you will get the message anyways. And from your answer, I believe you are getting the message -even when the app is not running- but something within your GCMIntentReceiver is making your app crash. I would suggest you run the app with logcat on and check what error is thrown when your app crashes -my money is on the class name within the intent in the GCM receiver.

You ask what should you do when you get the message. Well, displaying a notification is the obvious answer, otherwise the user will not know what happened, and this way they have the option to click on the notification and perform whatever action you want. All of these needs to be within the GCMIntentReceiver that listens for the GCM messages.

Anyways, this is a complex topic, and a lot of it is up to you as well. If you want to avoid all the hassle of implementing a system from scratch, I have an asset in the Unity Store that handles this very behaviour -and extends it to android as well:

Easy Cross-Platform Notifications

It comes with a full step-by-step guide that will help you all the way through -and in the end you will have a truly cross-platform notification system that can handle messages in between iOS and android devices!

share|improve this answer
I've solved my problem. I found an open source solution that works great. – cchomiak Aug 6 '13 at 6:25

It sounds like the problem you're encountering is due to a bug or implementation error in the GCM plugin you're using. If your app throws an error when it recieves a GCM notification while not active, that means that it's having an issue displaying the message correctly.

I see that the plugin was recently updated, so perhaps the latest version will solve your issue.

However, in my opinion, the easiest way to set up push notifications is to use a 3rd party service that provides both a plugin and notification delivery system.

There are a few reasons for this:

  • Many 3rd party push notification services provide plugins and instructions on how to get things set up correctly that are up to date and well tested.
  • Delivering a large number of notifications requires a significant amount of backend engineering work, and most open source solutions are unreliable or begin to fail after a high enough notification volume.
  • 3rd party push notification service provides are relatively inexpensive, or even free in many cases.

Here are some good 3rd party services that you can check out that have Unity push notification support for Android and iOS:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.