Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android : Unable to display multiple lines of text in Notification

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.

like image 362
Vipul J Avatar asked Oct 01 '22 17:10

Vipul J


1 Answers

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.

like image 153
Vipul J Avatar answered Oct 05 '22 11:10

Vipul J