abh22ishek
abh22ishek

Reputation: 2671

How can I force a notification to display text in multiple lines?

My status bar notification message is too long, so I want to display it on multiple lines but i don't know why its not displaying that way.

Here is my code:

String msg = "text1 text2 text3 text4 text5";

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);

mBuilder.setContentTitle(context.getResources().getString(R.string.time_to_brush_title));
mBuilder.setContentText(msg);
mBuilder.setTicker(context.getResources().getString(R.string.time_to_brush_title));
mBuilder.setSmallIcon(R.drawable.ic_launcher);
mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(msg));

However, This is what the notification bar contains:

text1 text2 text3 ...

Upvotes: 2

Views: 1946

Answers (1)

NullByte
NullByte

Reputation: 165

If you want to use this kind of notification in 4.1> then use

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
    .setSmallIcon(R.drawable.notification_icon)
    .setContentTitle("Event tracker")
    .setContentText("Events received")
NotificationCompat.InboxStyle inboxStyle =
        new NotificationCompat.InboxStyle();
String[] events = new String[6];
// Sets a title for the Inbox in expanded layout
inboxStyle.setBigContentTitle("Event tracker details:");
...
// Moves events into the expanded layout
for (int i=0; i < events.length; i++) {

    inboxStyle.addLine(events[i]);
}
// Moves the expanded layout object into the notification object.
mBuilder.setStyle(inBoxStyle);

here's the reference link https://developer.android.com/guide/topics/ui/notifiers/notifications.html

Upvotes: 1

Related Questions