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());
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.
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.
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.
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.
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.
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.
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();
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With