Tuesday, August 21, 2018

Android showing Push Notification in Multiline

When you show longer text in notification message, you can notice that the text is stripped away. So if want to show the full text in multiple lines, you need to use additional setStyle() method while your building the notification builder.


int icon = R.drawable.ic_notification;
 
int mNotificationId = 001;
 
PendingIntent resultPendingIntent =
        PendingIntent.getActivity(
                mContext,
                0,
                intent,
                PendingIntent.FLAG_CANCEL_CURRENT
        );
 
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
        mContext);
Notification notification = mBuilder.setSmallIcon(icon).setTicker(title).setWhen(0)
        .setAutoCancel(true)
        .setContentTitle(title)
        .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
        .setContentIntent(resultPendingIntent)
        .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
        .setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), R.mipmap.ic_logo))
        .setContentText(message).build();
 
NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(mNotificationId, notification);

No comments:

Post a Comment

AJAX - Quick Guide