【问题标题】:Android notification manager helpAndroid 通知管理器帮助
【发布时间】:2011-03-14 05:48:50
【问题描述】:

我目前正在研究 android 通知。有没有办法将来自应用程序的所有通知显示为单个通知,并在 android 通知窗口中显示数字。单击此按钮会将用户重定向到应用程序中带有单独通知的视图。还有有没有办法为每个通知设置活动,以便根据点击的通知将用户重定向到适当的活动。

【问题讨论】:

    标签: android notifications notificationmanager


    【解决方案1】:

    您可以附加一个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;
    

    希望它会有所帮助。

    【讨论】:

    • 谢谢 ackio。我会检查这个。如果android有任何默认功能会更好。我经历了这个:developer.android.com/guide/topics/ui/notifiers/…他们没有解释更新通知。
    • 更新只是意味着使用相同的 ID 调用 NotificationManager::notify。如果 ID 不同,将添加新通知,否则更新现有通知。
    • 在那篇文章中,我读到了“消息应用程序更新现有通知以显示收到的新消息总数”这一行。所以我相信这是可能的。
    • Atlast 我决定去柜台领取通知。最后 5 个通知将在通知管理器中可用。谢谢你帮助我。
    猜你喜欢
    • 2011-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-19
    • 1970-01-01
    • 2011-06-04
    • 1970-01-01
    相关资源
    最近更新 更多