问题描述
我在理解 setGroup()
方法.
I have a some troubles with understanding of goal of setGroup()
method.
如文档所述:
这是第一个问题:
我创建了一种显示自定义短信的方法:
I create a method which show a custom text message :
public static void showNotification(Context context, String title, String message, PendingIntent pendingIntent) {
notificationMessages.add(message);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setContentTitle(title)
.setContentText(message)
.setAutoCancel(true)
// .setGroupSummary(true)
.setSmallIcon(R.drawable.ic_launcher)
.setContentInfo("" + (notificationMessages.size()))
/*.setGroup(++i + "")*/;
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
inboxStyle.setBigContentTitle(title);
for (int i = 0; i < notificationMessages.size(); i++) {
inboxStyle.addLine(notificationMessages.get(i));
}
builder.setContentIntent(pendingIntent);
builder.setStyle(inboxStyle);
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = builder.build();
mNotificationManager.notify(0, notification);
}
并使用notificationID
,setGroup
和setGroupSummary
方法播放.
public static void showNotification(Context context, String title, String message, PendingIntent pendingIntent) {
notificationMessages.add(message);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setContentTitle(title)
.setContentText(message)
.setAutoCancel(true)
// .setGroupSummary(true)
.setSmallIcon(R.drawable.ic_launcher)
.setContentInfo("" + (notificationMessages.size()))
.setGroup(GROUP_KEY);
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
inboxStyle.setBigContentTitle(title);
for (int i = 0; i < notificationMessages.size(); i++) {
inboxStyle.addLine(notificationMessages.get(i));
}
builder.setContentIntent(pendingIntent);
builder.setStyle(inboxStyle);
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = builder.build();
mNotificationManager.notify(new Random().nextInt(3), notification);
}
但是,没有视觉变化不管我是否发表评论.因此,对我来说,了解这种方法的目的是很困难的.
But, no visual changescomes if I commented lines or not. So here is a stuck for me in understanding of purpose of this method.
推荐答案
来自官方文档:
http://developer.android.com/preview/features/notification -updates.html
意味着setGroup
仅在设备支持的情况下才会有所不同.
Meaning the setGroup
will only make a difference if the device supports it.
支持该功能的设备为:
- Android Wear设备.显示远程通知时,您可以将它们分组在一起
- AndroidN.运行Android N开发人员预览版的设备(或将来的正式N版本)将一起显示一组通知
以下博客文章显示了它们如何在Android N上工作: https://medium.com/exploring-android/android-n-introducing-upgraded-notifications-d4dd98a7ca92
The following blog post shows how those work on Android N: https://medium.com/exploring-android/android-n-introducing-upgraded-notifications-d4dd98a7ca92
bellow是一组外观的渲染:
bellow is a render of that a group looks like:
这意味着setGroup
对于运行以下API23的设备(包括棉花糖,棒棒糖,奇巧等)不会产生任何影响.
That means that setGroup
will make no difference on devices running anything bellow API23, that includes, Marshamallow, Lollipop, KitKat, etc.
这篇关于Notification.Builder中的setGroup()的用途是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!