我尝试在通知中使用BigTextStyle
显示多行文字,但无法这样做。我正在使用下面的代码。
public void sendNotification(View view) {
String msgText = "Jeally Bean Notification example!! "
+ "where you will see three different kind of notification. "
+ "you can even put the very long string here.";
NotificationManager notificationManager = getNotificationManager();
PendingIntent pi = getPendingIntent();
android.app.Notification.Builder builder = new Notification.Builder(
this);
builder.setContentTitle("Big text Notofication")
.setContentText("Big text Notification")
.setSmallIcon(R.drawable.ic_launcher).setAutoCancel(true)
.setPriority(Notification.PRIORITY_HIGH)
.addAction(R.drawable.ic_launcher, "show activity", pi);
Notification notification = new Notification.BigTextStyle(builder)
.bigText(msgText).build();
notificationManager.notify(0, notification);
}
public NotificationManager getNotificationManager() {
return (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
}
public PendingIntent getPendingIntent() {
return PendingIntent.getActivity(this, 0, new Intent(this,
MainActivity.class), 0);
}
我甚至无法在通知中看到'msgText'。知道为什么吗? 谢谢你的帮助。
答案 0 :(得分:4)
解决!
代码很好,只是没有足够的空间进行大通知。当我断开数据线时,它以所需的方式显示。 : - )
感谢所有试图提供帮助的人。
答案 1 :(得分:3)
只需将通知样式设置为BigText
即可{{1}}
答案 2 :(得分:0)
尝试设置内容意图值。
Notification.Builder builder = new Notification.Builder(this);
builder.setContentTitle("Big text Notification")
.setContentText("Big text Notification")
.setSmallIcon(R.drawable.ic_launcher)
.setAutoCancel(true)
.setContentIntent(pi) // <- this new line
.setPriority(Notification.PRIORITY_HIGH)
.addAction(R.drawable.ic_launcher, "show activity", pi);
答案 3 :(得分:-3)
.setPriority(Notification.PRIORITY_HIGH)
- 这条线解决了我的问题。多线保存大小。