开发者

NotificationManager, multiple icons, but only one can launch activity

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 ico开发者_如何学编程n 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!


Use the number atribute in Notification object

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜