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.
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
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());
} }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.