2011-03-14 63 views
3

我目前正在调查android通知。有没有什么办法可以将所有来自应用程序的通知显示为一个单独的android通知窗口中的数字。点击此按钮会将用户重定向到应用程序中的单独通知视图。还有什么办法来设置每个通知的活动,以便用户将被重定向到基于点击通知的适当活动。Android通知管理器帮助

回答

6

您可以附上一个custom layout to your notification,其中包含一个计数器。并且当事件发生时增加计数器和update the notification。类似像下面的例子中:

Notification notification = new Notification(R.drawable.logo, name, System.currentTimeMillis()); 

    RemoteViews contentView = new RemoteViews(appContext.getPackageName(), R.layout.custom_layout); 

    contentView.setTextViewText(R.id.notification_text, Counter); 

notification.contentView = contentView; 

要将活动连接到通知:

 Intent notificationIntent = new Intent(appContext, MyActivity.class); 
     Bundle bundle = new Bundle(); 
     bundle.putInt(...); 
     notificationIntent.putExtras(bundle); 
     notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);   

     PendingIntent contentIntent = PendingIntent.getActivity(appContext, (int)System.currentTimeMillis(), notificationIntent, 0); 
     notification.contentIntent = contentIntent; 

希望这将有助于。

+1

谢谢ackio。我会检查这一点。如果有android的任何默认功能将会更好。 我已经通过这个:http://developer.android.com/guide/topics/ui/notifiers/notifications.html#Updating 他们没有解释关于更新通知。 – 2011-03-17 12:44:57

+1

更新仅仅意味着使用相同的ID调用NotificationManager :: notify。如果ID不同,则会添加新通知,否则会更新现有通知。 – ackio 2011-03-18 04:27:45

+0

在那篇文章中,我读过这一行“消息传递应用程序更新现有通知以显示收到的新消息总数”。所以我相信它是可能的。 – 2011-03-18 06:51:17