Skip to content
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
Cannot retrieve contributors at this time

Receive rich push notifications

You can attach image files to your Android notifications. Adding visual components can significantly increase your user's engagement with push notifications.

Handle the incoming rich push message (FCM)

If the app is in the foreground, the push message will be handled by the app that extends the FirebaseMessagingService class and is declared in the manifest file in the following way:

        <action android:name="" />

Important: The class that contains the onMessageReceived() implementation handles the data that is received.

If the push message contains a Media URL, the URL will be available in the RemoteMessage parameter that is passed to the onMessageReceived() function. The key to be used is attachment-url as shown in the following code sample:

public class MyFirebaseMessagingService extends FirebaseMessagingService {
        public void onMessageReceived(RemoteMessage remoteMessage) {
      Log.d("Remote Message", "RemoteMessage: " + remoteMessage.toString());
            // Check if message contains a data payload.
            if (remoteMessage.getData().size() > 0) {
                Log.d("Remote Message", "RemoteMessage: " + remoteMessage.getData());
private void sendNotification(RemoteMessage message) {
        Intent intent = new Intent(this, MainActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT);

     String channelId = getString(R.string.default_notification_channel_id);
     Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
     NotificationCompat.Builder notificationBuilder =
                new NotificationCompat.Builder(this, channelId)
    //Handle image url if present in the push message 
        String attachmentUrl = message.getData().get("attachment-url");
    if (attachmentUrl != null) { 
    Bitmap image = getBitmapFromURL(attachmentUrl); 
    if (image != null) { 
      notificationBuilder.setStyle(new        NotificationCompat.BigPictureStyle().bigPicture(image)); 

     NotificationManager notificationManager =
              (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

     // Since android Oreo notification channel is needed.
     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel channel = new NotificationChannel(channelId,
                    "Channel human readable title",

     notificationManager.notify(0 /* ID of notification */,;

Important: When you set NotificationCompat.BigPictureStyle, large images might not be displayed. To ensure that large images are always displayed, set the native Notification.BigPictureStyle.

Sample rich push notification

Here is an example of a rich push notification with an image:

For more information about rich push notifications with Android, see Engage with Rich Notifications.