5

我正在尝试使用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”。知道为什么吗?感谢您的帮助。

4

4 回答 4

4

解决了!

代码很好,只是没有足够的空间进行大通知。当我断开数据线时,它以所需的方式显示。:-)

感谢所有试图提供帮助的人。

于 2014-01-30T10:44:01.973 回答
4

只需将通知样式设置为 BigText

   NotificationCompat.BigTextStyle bigStyle =
   new NotificationCompat.BigTextStyle();
   bigStyle.setBigContentTitle(title);
   bigStyle.bigText(messageBody);
   builder.setStyle(bigStyle);
于 2016-12-02T04:38:52.377 回答
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);
于 2014-01-30T06:45:51.613 回答
-4

.setPriority(Notification.PRIORITY_HIGH)- 这条线解决了我的问题。多行保存大小。

于 2015-11-04T20:37:26.063 回答