Adding Local Notification in Cocos2DX C++ (CPP)
I was trying to implement the Local Notification system in my upcoming Cocos2DX CPP game. I tried to look up for existing solutions and easily found one on Github. It supported both iOS and Android platforms.
https://github.com/kobakei/CCLocalNotification
Everything was awesome, except for the fact that the project was like 3 Years old, and a lot of water had passed since then.
So someone had had this outdated linking issue and found a solution to it.
http://discuss.cocos2d-x.org/t/cocos2d-x-local-notification/19192
Where a developer Elrinth, thankfully put up the fixed code. Linked here:
http://pastebin.com/fXHTdXhZ
Everything was awesome again, except for the fact that the response was again 1 year old (at the time of writing this). So when I compiled the code, I got the following error:
Error: package android.support.v4.app does not exist
Awesome! So the elusive quest for solution began again. The search was a bit annoying because most of the solutions were using Gradle for Android Studio, whereas I was using the old school console to compile my projects.
Anyway, I finally got the thing working. As following:
1) First import the files mentioned in the above GitHub link
2) Use the updated code mentioned in the PasteBin link
3) If you get the error as shown above, do the following:
To fix the Android Support v4 issue, copy the file mentioned below:
<ANDROID SDK FOLDER>/extras/android/support/v4/android-support-v4.jar
To the "libs" folder of your Cocos2dX Android project directory. So it looks somewhat like below:
<COCOS2D PROJECT ROOT>/proj.android/libs/android-support-v4.jar
Then in the file mentioned below:
<COCOS2D PROJECT ROOT>/proj.android/src/org/cocos2dx/cpp/LocalNotificationReceiver.java
On line number 2, change this line to include your project's bundle id:
import com.MyCompany.AwesomeGame.R;
And then on line number 22, change this
Intent intent2 = new Intent(context, Cocos2dxActivity.class);
to this
Intent intent2 = new Intent(context, AppActivity.class);
That's it. Put the code to schedule the notification on specific any event and then compile it. You should get an awesome little notification right on top.
The result was tested only on Android as of now. But it should work on iOS as well.
Don't forget to Like and Share if you find this useful!
https://github.com/kobakei/CCLocalNotification
Everything was awesome, except for the fact that the project was like 3 Years old, and a lot of water had passed since then.
So someone had had this outdated linking issue and found a solution to it.
http://discuss.cocos2d-x.org/t/cocos2d-x-local-notification/19192
Where a developer Elrinth, thankfully put up the fixed code. Linked here:
http://pastebin.com/fXHTdXhZ
Everything was awesome again, except for the fact that the response was again 1 year old (at the time of writing this). So when I compiled the code, I got the following error:
Error: package android.support.v4.app does not exist
Awesome! So the elusive quest for solution began again. The search was a bit annoying because most of the solutions were using Gradle for Android Studio, whereas I was using the old school console to compile my projects.
Anyway, I finally got the thing working. As following:
1) First import the files mentioned in the above GitHub link
2) Use the updated code mentioned in the PasteBin link
3) If you get the error as shown above, do the following:
To fix the Android Support v4 issue, copy the file mentioned below:
To the "libs" folder of your Cocos2dX Android project directory. So it looks somewhat like below:
Then in the file mentioned below:
<COCOS2D PROJECT ROOT>
On line number 2, change this line to include your project's bundle id:
import com.MyCompany.AwesomeGame.R;
And then on line number 22, change this
Intent intent2 = new Intent(context, Cocos2dxActivity.class);
to this
Intent intent2 = new Intent(context, AppActivity.class);
That's it. Put the code to schedule the notification on specific any event and then compile it. You should get an awesome little notification right on top.
The result was tested only on Android as of now. But it should work on iOS as well.
Don't forget to Like and Share if you find this useful!
Comments
Your post helped me to successfully run the local notification code. Thanks..
But whn i click on show notification i don't get any notification. What should i do now, i am not getting any error though.