Android通知 - 显示完整消息 [英] Android Notification- Display full message
问题描述
我的Android应用程序必须能够向一大群人发送短警报。明显的地方是在通知中心。完整的通知显示在代码中没有问题,但在通知中心,用户只能看到前几个单词,然后看到一个省略号。通知时间不长,最多只有10-15个字。
我的代码来建立通知在这里
<$>我怎样才能使文本换行到新行? p $ p $
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.splash)
.setContentTitle(Student Engauge)
.setContentText(extras.getString(message))
.setAutoCancel(true)
.setTicker(extras.getString(message));
final int notificationId = 1;
NotificationManager nm =(NotificationManager)getApplicationContext()
.getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(notificationId,mBuilder.build());
要显示大量文本,请使用BigTextStyle。以下是 BigTextStyle 中给出的示例代码。此通知将包含一行文本,如果需要,它将展开为更多行。
通知noti = new Notification.Builder()
.setContentTitle(New mail from+ sender.toString())
.setContentText(subject)
.setSmallIcon(R.drawable.new_mail)
.setLargeIcon(aBitmap)
.setStyle(new Notification.BigTextStyle()
.bigText(aVeryLongString))
.build();
对于android支持库
Notification noti = new Notification.Builder()
.setContentTitle(New mail from+ sender.toString())
.setContentText(subject )
.setSmallIcon(R.drawable.new_mail)
.setLargeIcon(aBitmap)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(aVeryLongString))
。建立();
My Android Application has to be able to send short alerts out to a large group of people. The obvious place to do this is in the notification center. The full notification shows up in the ticker without a problem, but in the notification center a user can only see the first couple words and then an elipsis. The notifications are not long at all, just 10-15 words at the most. How can I make the text wrap down to a new line?
My code to build the notifications is here
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.splash)
.setContentTitle("Student Engauge")
.setContentText(extras.getString("message"))
.setAutoCancel(true)
.setTicker(extras.getString("message"));
final int notificationId = 1;
NotificationManager nm = (NotificationManager) getApplicationContext()
.getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(notificationId, mBuilder.build());
To show large chunk of text, use the BigTextStyle. Here is a sample code as given in BigTextStyle. This notification will one line of text and will expand to more lines if needed.
Notification noti = new Notification.Builder()
.setContentTitle("New mail from " + sender.toString())
.setContentText(subject)
.setSmallIcon(R.drawable.new_mail)
.setLargeIcon(aBitmap)
.setStyle(new Notification.BigTextStyle()
.bigText(aVeryLongString))
.build();
For android support library
Notification noti = new Notification.Builder()
.setContentTitle("New mail from " + sender.toString())
.setContentText(subject)
.setSmallIcon(R.drawable.new_mail)
.setLargeIcon(aBitmap)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(aVeryLongString))
.build();
这篇关于Android通知 - 显示完整消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!