Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

1 Answer 1

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. github.com/kskkbys/unity-gcm –  cchomiak Aug 6 '13 at 6:25

Your Answer

 
discard

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.