Android Notifications with Images and Text Together

21 / Aug / 2014 by Anand Rai 1 comments

We all love notifications of android applications and its notification bar. But it would be much better if we can show the user the rich notifications instead of those boring text notifications. But it is not simple task that it sounds to be.

The problem is, when we try to display image with text then what we get only image or text depending on devices but not simultaneouly. If we get the text then to reveal the image we will have to expand the image by gesture and vice-versa otherwise.

Here, I will show you how to achieve this functionality. I discovered two solution for this problem.

Here is my fist solution that utilize Styles:

[sourcecode language=”java”]
NotificationManager notificationManager = (NotificationManager)

Intent notificationIntent = new Intent(context, MainActivity.class);


PendingIntent intent =
PendingIntent.getActivity(context, 0,

Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
String message="Hello Notification with image";
String title="Notification !!!";
int icon = R.drawable.ic_launcher;
long when = System.currentTimeMillis();

notification = new NotificationCompat.Builder(context)
.setStyle(new NotificationCompat.BigPictureStyle()

notification.flags |= Notification.FLAG_AUTO_CANCEL;

// Play default notification sound
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_VIBRATE;
notificationManager.notify(0, notification);

In above code the I am calling Builder.setStyle() method passing new instance of NotificationCompat.BigPictureStyle() and providing it with a bitmap and message by calling its respective methods.

And here is another solution that utilzes Dynamic Layout:

[sourcecode language=”java”]
String title="Notification !!!";
int icon = R.drawable.ic_launcher;
long when = System.currentTimeMillis();

Notification notification = new Notification(icon, title, when);

NotificationManager mNotificationManager =

RemoteViews contentView = new RemoteViews
(getPackageName(), R.layout.custom_notification);
contentView.setTextViewText(, title);
"This is a custom layout");
notification.contentView = contentView;

Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this,0,
notificationIntent, 0);
notification.contentIntent = contentIntent;

notification.flags |=
Notification.FLAG_NO_CLEAR; //Do not clear the notification
notification.defaults |= Notification.DEFAULT_LIGHTS; // LED
notification.defaults |= Notification.DEFAULT_VIBRATE;//Vibration
notification.defaults |= Notification.DEFAULT_SOUND; // Sound

mNotificationManager.notify(1, notification);

In this code I am using the RemoteViews class to set the image and text together. For getting this class to work we need to pass two argument, first is application package and other is layout file that describes an ImageView and two TextView.

And that is all we need to implement this feature correctly.

Have a nice time with your rich notifications. 😉


comments (1 “Android Notifications with Images and Text Together”)

Leave a Reply

Your email address will not be published. Required fields are marked *