Android Notification- Display full message
Solution 1
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();
Solution 2
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:
- 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.
- 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
Related videos on Youtube
centree
Updated on October 12, 2020Comments
-
centree over 3 years
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 almost 11 yearsBig Views aren't supported before 4.1, I'd like something that's more supported
-
likejudo about 10 years
setStyle(new NotificationCompat.BigTextStyle().bigText(aVeryLongString))
-
pmont about 10 years@centree Use NotificationCompat to support the newer notification features on older devices. developer.android.com/reference/android/support/v4/app/…
-
Frank almost 10 years@pmont the compat lib does still not support bigText for Android 4.0
-
Rahul Matte about 8 yearsThis collapse other notifications