Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Notification- Display full message

Tags:

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()); 
like image 709
centree Avatar asked May 09 '13 20:05

centree


People also ask

How do I read the whole notification?

1 I can just "pull down" the notification (using one finger) or pinch-zoom it (using two fingers) to see the full text: first, pull down the notification bar. then pull down the single notification, where the text is cropped.

How do I get rid of expand notifications?

To remove a persistent notification on Android as fast as possible, first, press-and-hold on it. Alternatively, swipe the notification left or right to reveal a gear icon on either side, and then tap on it. The notification expands. Tap on “Turn off notifications” at the bottom.

What is notification in Android?

Android-Notifications. A notification is a message you can display to the user outside of your application's normal UI. When you tell the system to issue a notification, it first appears as an icon in the notification area. To see the details of the notification, the user opens the notification drawer.

Can I expand the text in Android notifications?

Expanded notifications are only available from Android 4.1, read here Android 2.3.3 uses the old notifications without expansion. You must user a shorter text, cut your text (and show the full text when user click on it) or adapt the text if you are showing the notification in Android 4.1 or older.

How to show a full-screen intent in Android notifications?

Notify while the app on the foreground. In order to show a full-screen intent, we need to first build the notification and set the full-screen intent to the notification. To build the intent we need a pending intent, which can be achieved using PendingIntent. Don’t forget to add in your AndroidManifest.xml’s Activity the following as well: 2.

How to view the details of the notification in Android emulator?

To see the details of the notification, you will have to select the icon which will display notification drawer having detail about the notification. While working with emulator with virtual device, you will have to click and drag down the status bar to expand it which will give you detail as follows.


2 Answers

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(); 
like image 59
Aswin Rajendiran Avatar answered Oct 12 '22 11:10

Aswin Rajendiran


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
like image 30
erdemlal Avatar answered Oct 12 '22 11:10

erdemlal