Skip to content

Android Notification Builder — Complete Guide

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about Android Notification Builder. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.

The Problem

Your notification looks tiny with just a title and text. You can't expand it, or the big picture style doesn't show the image.

Wrong Approach ❌

// Basic notification — no expandable content
val notification = NotificationCompat.Builder(this, CHANNEL_ID)
    .setContentTitle("New Message")
    .setContentText("Hello!") // Short text only
    .setSmallIcon(R.drawable.ic_message)
    .build()

Output: Notification with no expandable content. Long text is truncated.

Right Approach ✅

// Expandable notification with BigTextStyle
val bigTextNotification = NotificationCompat.Builder(this, CHANNEL_ID)
    .setContentTitle("New Message from Alice")
    .setContentText("Hey, are you coming to the party tonight?")
    .setSmallIcon(R.drawable.ic_message)
    .setStyle(NotificationCompat.BigTextStyle()
        .bigText("Hey, are you coming to the party tonight? It starts at 8pm and everyone will be there!")
        .setBigContentTitle("Alice Smith")
        .setSummaryText("1 new message")
    )
    .setPriority(NotificationCompat.PRIORITY_HIGH)
    .setAutoCancel(true)
    .setColor(ContextCompat.getColor(this, R.color.primary))
    .build()

// BigPictureStyle for image notifications
val bigPictureNotification = NotificationCompat.Builder(this, CHANNEL_ID)
    .setContentTitle("New Photo")
    .setContentText("Alice shared a photo")
    .setSmallIcon(R.drawable.ic_photo)
    .setStyle(NotificationCompat.BigPictureStyle()
        .bigPicture(bitmap) // The image to show
        .bigLargeIcon(null) // Hide the large icon when expanded
    )
    .build()

// InboxStyle for multiple messages
val inboxNotification = NotificationCompat.Builder(this, CHANNEL_ID)
    .setContentTitle("3 new messages")
    .setStyle(NotificationCompat.InboxStyle()
        .addLine("Alice: Hey!")
        .addLine("Bob: Are you free?")
        .addLine("Charlie: Meeting at 3")
        .setSummaryText("3 new messages")
    )
    .build()

Output: Expandable notifications with proper styling.

Prevention

  • Use BigTextStyle for long text content.
  • Use BigPictureStyle for image-sharing apps.
  • Use InboxStyle for messaging apps with multiple messages.
  • Always set setColor() to match your app's brand color.

Common Mistakes with notification Builder

  1. Forgetting deriving (Show, Eq) on custom data types needed for debugging
  2. Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
  3. Using head and tail instead of pattern matching, causing runtime errors on empty lists

These mistakes appear frequently in real-world Android code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### How big can a big picture be?

The image should be no larger than 1920x1920px. Android scales it to fit the notification. Use Glide or Coil to load and resize images before setting.

### What is the difference between setContentText and BigTextStyle.bigText?

setContentText shows in the collapsed (1-line) notification. bigText shows when the user expands the notification. Both should be set for best UX.

### Can I use MediaStyle for music player notifications?

Yes. NotificationCompat.MediaStyle displays media transport controls. Use setMediaSession() to link to your MediaSession for lock screen controls.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro