Using push notifications in Android with Cocos2D-X (C++)

Hello,

I am currently developing an application capable of receiving push notifications from a local server. Is there any documentation or tutorials for Android with C++ using Cocos2D-X?

Platform Information:
Android 4.1.2+
Cocos2D-X 3.0 Alpha-Pre
Visual Studio 2012

Thanks for any reply!

PS: I am setting the notifications following the Google Cloud Messaging Tutorial (http://developer.android.com/google/gcm/gs.html)

It seems you can only accomplish this using JNI

Follow this guide:

http://developer.android.com/google/gcm/client.html

and implement your AsyncTasks behind JNI calls.

Where the response is coming from Java to C++, you have to use another JNI call going the other way and then use CCDirector to get to the running scene (to send this push message into the active CC2dx context.)

I am doing it easily enough in 2.2 and I assume it would be even easier with NativeActivity and 3.0

@corytrese Thanks for your answer! I will start testing it that way after I finish the local server.

A friend of mine recommended me to use www.parse.com for an easy way to work around push notifications, could it be possible to work with it in Cocos2D-X?

I will probably use the first way, but it would be good to have other options available! Thanks for the feedback :D!

I am not able to understand the pricing or parese.com… also that might be because I am new to push notofication in egeneral. @corytrese how do you do AsyncTasks in java for this. I am using cocos2d-x 2.2.3… could you share some code…

Can anyone help in this regard… I tried following the tutorial http://developer.android.com/google/gcm/client.html76 and whereever there is a R.somevariable I get an error can someone pls guide… ???

java noob here. I added the values in the res/resources, main and other stuff got the DEVICE_ID and also sent message through hurlit and got response as message success with message id. I am new to sending push notifications, so is that it?I mean I still didn’t receive any message on the device. Also on the device I am getting black screen and the original app/game is crashing.

I get the following error in logcat

11-17 20:19:12.914: E/cocos2d-x assert(13138): /Volumes/MK_/Users/siddharthshekar/Documents/_Projects/cocos2d-x-2.2.3/projects/santassaviour/proj.android/…/…/…/cocos2dx/platform/android/CCApplication.cpp function:sharedApplication line:60

11-17 20:19:12.914: A/libc(13138): Fatal signal 11 (SIGSEGV) at 0×00000000 (code=1), thread 13161 (Thread-4530)

Are you sure your JNI calls and their definitions are correct? It’s been a while so I’m a little hazy but I remember getting a bunch of errors like that. The elusive libc errors aren’t very descriptive.

I was on 3.x at the time but I don’t think it’s a cocos related thing at all. I ended up solving my errors by using javah to generate the headers as part of my build step since it’s tricky to follow how to define it (remembering to use extern C so object names aren’t mangled in compilation and unaccessible during runtime, etc).
Some different commands to debug for different architectures:

alias ndkst="adb logcat | ndk-stack -sym ./obj/local" 
alias ndksta="adb logcat | ndk-stack -sym ./obj/local/armeabi"
alias ndksta7="adb logcat | ndk-stack -sym ./obj/local/armeabi-v7a"

Also try logging statements before and after JNI calls for more info.

Hopefully this helps.

No I am not using JNI. I scewed around a bit and found that if you comment the line setContext(this) it doesnt give the black screen and I was able to receieve the notification.

And I had to comment the if in onClick() becuase I couldny find R.id.send and R.id.Close (I think) so I think because of that I never got the button. Not sure. But I think since I commented those lined it got registered automatically. Also it could be because I used the game id in the developer console and device. I read somewhere that if both are same the device will get registered automatically.

But after all think I came to know that I need to keep track of the registration if of all devices to send push notifications to them. So I would need a server backend which I have no clue of as it is all very new to me. So looking into parse and other solutions untill I figure out how to make and maintain a backend ;).

Hey, You can go through with ShepHertz Push Notification API, provides various API’s for Push Notification across multiple platform.
You can find Sample Application to build Android as well as iOS app to use Push Notification in your App.You can read Wiki documentation pages added in sample for Push configuration on iOS and Android platform