Android 多重通知 [英] Android Multiple Notification

查看:11
本文介绍了Android 多重通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,用户可以在其中创建事件并为该事件设置通知.所以我想添加多个通知.我正在使用以下代码.

I have developing an App where the user can create event and set notification for that very event. So I want to add multiple notification. I am using the following code.

final Notification notifyDetails = new Notification(R.drawable.icon, "Myapp",calendar.getTimeInMillis());
Context context = getApplicationContext();
Intent notifyIntent = new Intent(context, ViewDoughnut.class);
PendingIntent pendingIntent = PendingIntent.getActivity(ViewCal.this, 0, notifyIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
notifyDetails.setLatestEventInfo(context, contentTitle, contentText, pendingIntent);
notifyDetails.flags = Notification.FLAG_ONGOING_EVENT;
mNotificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails);

当我使用上述代码添加事件并创建通知时,它工作正常.但是如果我添加另一个事件,没有创建新的通知,旧的只是更新.我想再添加一个通知.怎么做?此外,如果用户删除与其对应的事件,我想删除任何特定通知.怎么可能?

When I add an event and creating a notification using the above code, it is working fine. But if I add another event, no new notification created, the old one is just updated. I want to add one more notification. How to do it? Moreover, I want to delete any specific notification if the user delete the event corresponding to it. How it is possible?

推荐答案

我假设 SIMPLE_NOTIFICATION_ID 是一个常量?要获得单独的通知,您需要为每个通知使用不同的 ID.

I assume that SIMPLE_NOTIFICATION_ID is a constant? To have separate notifications you need to use a different ID for each one.

这篇关于Android 多重通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆