Cocos2d-x and Android GCM Notifications.

Hello,

I’m making a game where I have to integrate notifications android GCM.

The notification system is created, and if I get a notification when the application is closed everything is working properly.
But if I get a notification when the application is open, pendingIntent class opens a new intent (NotificationActivity) that closing a black screen appears.

I searched google any example that integrated notification system GCM, but found nothing.

Someone could help me. I would be very grateful.
Thank you.

1 Like

Have the same problem. But i am integrate Alarm Notificaton.
Problem with create Activity with Game:

Intent notificationIntent = new Intent(context, MyGameActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context,
NOTIFICATION_ID, notificationIntent,Intent.FLAG_ACTIVITY_NEW_TASK);

notification.setLatestEventInfo(context, note, title, contentIntent);

manger.notify(NOTIFICATION_ID++, notification);

Solved by this code

NotificationManager manger = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.icon,
“Game!”, System.currentTimeMillis());
Intent notificationIntent = new Intent(context, MyGame.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
Bundle extras = intent.getExtras();
String title = extras.getString(“title”);
String note = extras.getString(“note”);
int notifId = extras.getInt(“notifId”);
PendingIntent contentIntent = PendingIntent.getActivity(context,
notifId, notificationIntent,PendingIntent.FLAG_ONE_SHOT); // by add this important flag problem was solved
notification.setLatestEventInfo(context,note, title, contentIntent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.defaults |= Notification.DEFAULT_SOUND;
manger.notify(notifId, notification);

1 Like