27

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());
centree
  • 2,399
  • 7
  • 28
  • 32

2 Answers2

52

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();
Gelldur
  • 11,187
  • 7
  • 57
  • 68
Aswin Rajendiran
  • 3,399
  • 1
  • 21
  • 18
4

For Android 4.1 and later devices, big view is the most suitable solution to show large amount of text. For pre 4.1 devices, you can use custom notification layout to show more data like mentioned here. But you should keep in mind two things:

  1. From the official documentation

    Caution: When you use a custom notification layout, take special care to ensure that your custom layout works with different device orientations and resolutions. While this advice applies to all View layouts, it's especially important for notifications because the space in the notification drawer is very restricted. Don't make your custom layout too complex, and be sure to test it in various configurations.

  2. Custom notification layouts have some limitations. Too long texts are not shown fully, but 10-15 words probably fit to the custom layout. This answer has more info about the limitation of custom notification layouts
Community
  • 1
  • 1
erdemlal
  • 491
  • 5
  • 21