【问题标题】:NotificationManager, multiple icons, but only one can launch activityNotificationManager,多个图标,但只有一个可以启动活动
【发布时间】:2011-10-06 23:00:45
【问题描述】:

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

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

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

更大的问题。如果我使用多个图标和唯一 ID,Android (2.2) 将不会在超过 1 个意图待处理时正确启动 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);
}

感谢您的任何见解!

【问题讨论】:

    标签: android notifications statusbar


    【解决方案1】:

    在 Notification 对象中使用数字属性

    【讨论】:

    • 你能举个例子吗
    猜你喜欢
    • 2018-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-06
    相关资源
    最近更新 更多