Android NotificationCompat.InboxStyle的添加行不工作
我正在尝试制作一个聊天应用程序,我的用户将在其中收到通知。通知的数量如此之高,如果我为每个通知创建一个条目,那么它将填充所有位置,因此我考虑应用BigTextView通知或通知堆栈 我写了下面一段代码:Android NotificationCompat.InboxStyle的添加行不工作,android,android-intent,notifications,android-pendingintent,Android,Android Intent,Notifications,Android Pendingintent,我正在尝试制作一个聊天应用程序,我的用户将在其中收到通知。通知的数量如此之高,如果我为每个通知创建一个条目,那么它将填充所有位置,因此我考虑应用BigTextView通知或通知堆栈 我写了下面一段代码: NotificationManager notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); if(listMessage.size() &
NotificationManager notificationManager = (NotificationManager)
this.getSystemService(Context.NOTIFICATION_SERVICE);
if(listMessage.size() <= 5)
listMessage.add(messagetype + ":" + msg);
else
{
listMessage.remove(4);
listMessage.add(messagetype + ":" + msg);
}
Intent notificationIntent = new Intent(this, GcmActivity.class);
notificationIntent.putExtra("title", messagetype);
notificationIntent.putExtra("message", msg);
PendingIntent intent = PendingIntent.getActivity(this, 0,notificationIntent, 0);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
NotificationCompat.Builder mBuilder;
mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("My MESSENGER")
.setStyle(new NotificationCompat.BigTextStyle()
.bigText("MESSAGES"))
.setContentText(msg)
.setAutoCancel(true)
.setLights(Color.WHITE, 1000, 5000)
.setDefaults(Notification.DEFAULT_VIBRATE |
Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS)
.setContentIntent(intent);
NotificationCompat.InboxStyle inboxStyle =
new NotificationCompat.InboxStyle();
inboxStyle.setBigContentTitle("MESSAGES");
for(int j= 0;j < listMessage.size();j++)
{
inboxStyle.addLine(listMessage.get(j));
}
mBuilder.setStyle(inboxStyle);
notificationManager.notify(0, mBuilder.build());
NotificationManager NotificationManager=(NotificationManager)
this.getSystemService(Context.NOTIFICATION\u服务);
如果(listMessage.size()您可能没有通知的扩展视图。
您需要在通知中向下滑动(使用两个手指效果更好)。还注意到,默认情况下,仅当您的通知位于通知列表的顶部时,扩展视图才会显示。