Can we implement like the title i told in cocos2dx. I mean, when use not open app for 7 days(example). We will push a notification, can we implement it by Cocos to cross platform? Please help.
Asked
Active
Viewed 1,238 times
2 Answers
4
It can't be cross-platform. Because cocos2d-x doesn't handle that but no one is stopping you to implement it for different OS's on your own,
you can use macro definition CC_PLATFORM_TARGET to write target code.
Implement iOS like how to create local notifications in iphone app
Implement Android like Local Notifications in Android?
If you need help in writing obj-c/c++ hybrid code, How can I use C++ with Objective-C in XCode
Or JNI bridge Android Cocos2dX JNI Bridge

Community
- 1
- 1

sanchitgulati
- 456
- 2
- 8
-
Cool, if it helps, share the love – sanchitgulati Jul 24 '14 at 06:56
2
I don't understand what exactly you want, but I think for doing this you can use an AlarmManager like this :
Calendar cal = Calendar.getInstance();
cal.add(Calendar.HOUR, heure); //choose here for a week
cal.add(Calendar.MINUTE, minute);
Intent intent = new Intent(this, MyBroadcastReceiver.class);
PendingIntent sender = PendingIntent.getBroadcast(this, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager) this
.getSystemService(Context.ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender);
and user a BroadcastReceiver for the notification like this :
public class MyBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Intent resultIntent = new Intent(context,
YourActivity.class); //to open when click the notification
resultIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
// Because clicking the notification opens a new ("special") activity,
// there's no need to create an artificial back stack.
PendingIntent resultPendingIntent = PendingIntent.getActivity(context,
0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Notification.Builder mBuilder = new Notification.Builder(context)
.setSmallIcon(R.drawable.courier_blanc)
.setContentTitle("Title")
.setContentText("Message");
mBuilder.setAutoCancel(true); //TODO enlever pour le mettre avec l'intent
mBuilder.setPriority(Notification.PRIORITY_MAX);
mBuilder.setContentIntent(resultPendingIntent);
// Sets an ID for the notification
int mNotificationId = 001;
// Gets an instance of the NotificationManager service
NotificationManager mNotifyMgr = (NotificationManager) context
.getSystemService(Application.NOTIFICATION_SERVICE);
// Builds the notification and issues it.
mNotifyMgr.notify(mNotificationId, mBuilder.build());
} }

Rajeev Barnwal
- 1,349
- 11
- 14

odiiil
- 276
- 1
- 2
- 9
-
Thank odiiil, This is only for android, i'm using cocos2dx to develop a mini game, so i want to implement by C++ – Lex Nguyen Jul 24 '14 at 06:46
-