首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Cocos2dx:在应用程序关闭时推送通知

Cocos2dx:在应用程序关闭时推送通知
EN

Stack Overflow用户
提问于 2014-07-24 06:36:54
回答 2查看 1.2K关注 0票数 1

我们能否像我在cocos2dx中告诉的标题那样实现。我的意思是,当使用7天不开放应用程序(例如)。我们会推动一个通知,我们能实现它由Cocos跨平台吗?请帮帮忙。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-07-24 06:46:42

不能是跨平台的。因为cocos2d-x不能处理这个问题,但是没有人阻止你单独为不同的操作系统实现它,

您可以使用宏定义CC_PLATFORM_TARGET来编写目标代码。

像iOS一样实现how to create local notifications in iphone app

Local Notifications in Android?一样实现Android

如果您需要帮助编写obj-c/c++混合代码,How can I use C++ with Objective-C in XCode

或JNI桥Android Cocos2dX JNI Bridge

票数 4
EN

Stack Overflow用户

发布于 2014-07-24 06:44:28

我不明白您到底想要什么,但我认为要做到这一点,您可以使用这样的AlarmManager:

代码语言:javascript
复制
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);

并使用BroadcastReceiver作为通知,如下所示:

代码语言:javascript
复制
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());

} }
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24926675

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档