Raú*_*pez 29 notifications stack grouping android google-cloud-messaging
我不知道如何将两个或多个通知分组到一个并显示"你有两条新消息"这样的消息.
Sac*_*ise 33
从以下代码中注意的步骤.
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.
Run Code Online (Sandbox Code Playgroud)
使用以下代码创建通知并对其进行分组.在按钮单击中包含该功能.
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());
}
}
Run Code Online (Sandbox Code Playgroud)
对于单独的通知,请分配不同的NOTIFICATION_ID ..
归档时间: |
|
查看次数: |
35578 次 |
最近记录: |