NotificationManager,多个图标,但只有一个可以启动 Activity

发布于 2024-12-08 17:27:37 字数 1375 浏览 0 评论 0原文

我有一个可以从多个来源接收消息的应用程序。我想在状态栏上放置一个通知,让用户知道每个来源。

现在,如果我在调用中指定唯一的notifyId_: mNotificationManager.notify(notifyId_, notificationDetails);

Android 在状态栏上放置了多个图标,但我只想要一个图标。如果我使用相同的notifyId_,那么我会得到一个图标,但是当您查看通知详细信息时,只会列出一个图标。有没有办法让一个图标具有多个唯一 ID?

一个更大的问题。如果我使用多个图标和唯一 ID,当超过 1 个意图待处理时,Android (2.2) 将无法正确启动 PendingIntent。我已经测试了 3 个源,每个源都可以单独工作。一旦我在状态栏上有一个以上的创建者图标,就只能启动一个活动,其他人说: 发送内容意图失败挂起意图取消异常 窗口已经聚焦,忽略代码的焦点增益

看起来像这样:

int notifyId_ = 237;
public void createNotification(String source, String person)
{
    notifyId_++;
    Context context = getApplicationContext();

    Intent notifyIntent = new Intent(context, MessengingActivity.class);
    notifyIntent.putExtra("name", person);
    notifyIntent.putExtra("notifyId", notifyId_);

    PendingIntent pi = PendingIntent.getActivity(SentinelActivity.this, 0, notifyIntent, 
            Intent.FLAG_ACTIVITY_MULTIPLE_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);


    Notification notifyDetails = new Notification(R.drawable.icon, "Text message(s) from " + source, System.currentTimeMillis());
    notifyDetails.setLatestEventInfo(context, source, "Conversation updated", pi);
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    mNotificationManager.notify(notifyId_, notifyDetails);
}

感谢您的任何见解!

I have an application which can receive messages from multiple sources. I'd like to put a notification on the status bar letting the user know of each source.

Now, if I specify a unique notifyId_ in the call:
mNotificationManager.notify(notifyId_, notifyDetails);

Android puts multiple icons on the status bar, but I only want one icon. If I use the same notifyId_ then I get one icon, but then when you view the notification detail only one is listed. Is there some way to get one icon with multiple unique IDs?

A bigger problem. If I go with multiple icons and unique Ids, Android (2.2) will not properly launch the PendingIntent when more than 1 intent is pending. I have tested my 3 sources, each works alone. As soon as I have creater than one icon on the status bar, only one activity can be launched, the others say:
sending contentintent failed pendingintentcanceledexception
window already focused, ignoring focus gain of

Code looks like this:

int notifyId_ = 237;
public void createNotification(String source, String person)
{
    notifyId_++;
    Context context = getApplicationContext();

    Intent notifyIntent = new Intent(context, MessengingActivity.class);
    notifyIntent.putExtra("name", person);
    notifyIntent.putExtra("notifyId", notifyId_);

    PendingIntent pi = PendingIntent.getActivity(SentinelActivity.this, 0, notifyIntent, 
            Intent.FLAG_ACTIVITY_MULTIPLE_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);


    Notification notifyDetails = new Notification(R.drawable.icon, "Text message(s) from " + source, System.currentTimeMillis());
    notifyDetails.setLatestEventInfo(context, source, "Conversation updated", pi);
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    mNotificationManager.notify(notifyId_, notifyDetails);
}

thanks for any insight!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧时光的容颜 2024-12-15 17:27:38

使用Notification对象中的number属性

Use the number atribute in Notification object

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文