NotificationCompat.BigTextStyle内容在新通知中消失 [英] NotificationCompat.BigTextStyle Content disappears on new notification
问题描述
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) this.getSystemService(ns);
int icon = R.drawable.ic_launcher;
CharSequence tickerText = title;
long when = System.currentTimeMillis();
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
if(alarmSound == null){
alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
if(alarmSound == null){
alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
}
}
Intent intent = new Intent();
PendingIntent pendingIntent
= PendingIntent.getActivity(this, 0, intent, 0);
NotificationCompat.BigTextStyle bigxtstyle =
new NotificationCompat.BigTextStyle();
bigxtstyle.bigText(text);
bigxtstyle.setBigContentTitle(title);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setStyle(bigxtstyle)
.setSmallIcon(icon)
.setAutoCancel(true)
.setSound(alarmSound)
.setDeleteIntent(pendingIntent)
.setContentIntent(PendingIntent.getActivity(this, 0, new Intent(), 0));
Notification noti = mBuilder.build();
mNotificationManager.notify(notificationid++, noti);
此代码有效,并显示用自动换行广告的文本.但是,当发生后续通知时,先前的通知会丢失其文本.任何人都可以帮助解决此问题吗?可能是我设置不正确的东西,我是android api的新手.
This code works, and displays the text as advertised with word wrapping. However, when a subsequent notification happens the previous notification loses its text. Can anyone help resolve this issue? It could be something I'm setting incorrectly, I am new to the android apis.
推荐答案
默认情况下,Android仅显示一个展开的通知.您的通知不会丢失其内容,它只会被压缩并且仅显示正常的单行内容.但是似乎您没有指定此名称,因此压缩的通知为空.
Android only displays one expanded notification by default. Your notification doesn't lose its content, it just gets compressed and only shows the normal one-line content. But it seems that you don't specify this, therefore the compressed notification is empty.
您可以使用 setContentText()
设置单行文本.
You may use setContentTitle()
and setContentText()
to set the one-line texts.
这篇关于NotificationCompat.BigTextStyle内容在新通知中消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!