5

I am trying to display multiple lines of Text using BigTextStyle in Notification but unable to do so. I am using the code below.

public void sendNotification(View view) {
    String msgText = "Jeally Bean Notification example!! "
            + "where you will see three different kind of notification. "
            + "you can even put the very long string here.";

    NotificationManager notificationManager = getNotificationManager();
    PendingIntent pi = getPendingIntent();
    android.app.Notification.Builder builder = new Notification.Builder(
            this);
    builder.setContentTitle("Big text Notofication")
            .setContentText("Big text Notification")
            .setSmallIcon(R.drawable.ic_launcher).setAutoCancel(true)
            .setPriority(Notification.PRIORITY_HIGH)
            .addAction(R.drawable.ic_launcher, "show activity", pi);
    Notification notification = new Notification.BigTextStyle(builder)
            .bigText(msgText).build();

    notificationManager.notify(0, notification);
}

public NotificationManager getNotificationManager() {
    return (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
}

public PendingIntent getPendingIntent() {
    return PendingIntent.getActivity(this, 0, new Intent(this,
            MainActivity.class), 0);
}

I can't even see 'msgText' in the notification. Any idea why? Thanks for helping.

4 Answers 4

4

Solved!

Code was fine, its just that there was not enough space for big notification. When I disconnected data cable, it got displayed in desired manner. :-)

Thanks to all who tried to help.

3
  • Is there any way I can show notification in full expanded mode by default instead of pinch-expand. Thanks Nov 17, 2014 at 12:43
  • your code doesn't work for me. Have you changed anything in this? It just displays text in one line removing trailing text.
    – keen
    Dec 12, 2014 at 6:57
  • @AnandPrakash , as describe in answer, simply disconect the cable. Jan 2, 2015 at 12:50
4

Just set notification style to BigText

   NotificationCompat.BigTextStyle bigStyle =
   new NotificationCompat.BigTextStyle();
   bigStyle.setBigContentTitle(title);
   bigStyle.bigText(messageBody);
   builder.setStyle(bigStyle);
0

Try to set content intent value as well.

Notification.Builder builder = new Notification.Builder(this);
builder.setContentTitle("Big text Notification")
        .setContentText("Big text Notification")
        .setSmallIcon(R.drawable.ic_launcher)
        .setAutoCancel(true)

        .setContentIntent(pi) // <- this new line

        .setPriority(Notification.PRIORITY_HIGH)
        .addAction(R.drawable.ic_launcher, "show activity", pi);
0
-5

.setPriority(Notification.PRIORITY_HIGH) - this line solved my problem. The multiline conserve size.

2
  • priority has nothing to do with that developer.android.com/reference/android/app/… "Relative priority for this notification. Priority is an indication of how much of the user's valuable attention should be consumed by this notification. Low-priority notifications may be hidden from the user in certain situations, while the user might be interrupted for a higher-priority notification. The system will make a determination about how to interpret this priority when presenting the notification." Nov 16, 2015 at 17:14
  • you should never use priority just to make some bugfix. Priority is for priority. read the docs Feb 25, 2016 at 13:33

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.