Android : Unable to display multiple lines of text in Notification

15,179

Solution 1

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.

Solution 2

Just set notification style to BigText

   NotificationCompat.BigTextStyle bigStyle =
   new NotificationCompat.BigTextStyle();
   bigStyle.setBigContentTitle(title);
   bigStyle.bigText(messageBody);
   builder.setStyle(bigStyle);
Share:
15,179
Vipul J
Author by

Vipul J

Android | Deep Learning | Tensorflow

Updated on June 04, 2022

Comments

  • Vipul J
    Vipul J almost 2 years

    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.