如何分组像whatsapp的安卓通知?

我不知道如何将两个或多个通知分组到一个显示“你有两条新消息”这样的消息.

解决方法:

从以下代码中注意的步骤.

NotificationCompat.Builder:contains the UI specification and action information
NotificationCompat.Builder.build() :used to create notification (Which returns Notification object)
Notification.InBoxStyle: used to group the notifications belongs to same ID
notificationmanager.notify():to issue the notification.

使用以下代码创建通知并对其进行分组.在按钮单击中包含该功能.

private final int NOTIFICATION_ID = 237;
private static int value = 0;
Notification.InBoxStyle inBoxStyle = new Notification.InBoxStyle();
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.push_notify_icon);
public void buttonClicked(View v)
{
        value ++;
        if(v.getId() == R.id.btnCreateNotify){
            notificationmanager nManager = (notificationmanager) getSystemService(NOTIFICATION_SERVICE);
            Notification.Builder builder = new Notification.Builder(this);            
            builder.setContentTitle("Lanes");
            builder.setContentText("Notification from Lanes"+value);
            builder.setSmallIcon(R.drawable.ic_launcher);
            builder.setLargeIcon(bitmap);
            builder.setAutoCancel(true);
            inBoxStyle.setBigContentTitle("Enter Content Text");
            inBoxStyle.addLine("hi events "+value);
            builder.setStyle(inBoxStyle);
            nManager.notify("App Name",NOTIFICATION_ID,builder.build());
        }
}

对于单独的通知,请分配不同的NOTIFICATION_ID ..

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...