gpt4 book ai didi

android - NotificationCompat.InboxStyle 的添加行不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 12:33:58 25 4
gpt4 key购买 nike

我正在尝试制作一个聊天应用程序,我的用户将在其中收到通知。通知量如此之大,如果我为每个通知创建一个条目,那么它会填满所有的地方,所以我想到应用 BigTextView 通知或 Stack of notifications。

我在下面写了一段代码:

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());

这似乎没有在通知中添加行。它只显示 setContentText 并且什么都不显示。

最佳答案

您可能没有通知的展开 View 。您需要在通知中向下滑动(用两根手指效果更好)。

关于android - NotificationCompat.InboxStyle 的添加行不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25288622/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com