How to create Custom Notification in android

16,509

Solution 1

Notification views

Normal View - A notification in normal view appears in an area that’s up to 64 dp tall. Even if you create a notification with a big view style, it will appear in normal view until it’s expanded.

Content title
Large icon
Content text
Content info
Small icon
Notification time

Normal View Like enter image description here

Big View - A notification’s big view appears only when the notification is expanded, which happens when the notification is at the top of the notification drawer, or when the user expands the notification with a gesture. Expanded notifications were first introduced in Android 4.1 JellyBean [API 16]. Expandable notifications were designed to support rich notification style objects called Notification.Style.

Big View Like

enter image description here

Go to this link expandable-notifications-android

More information on official docs

Solution 2

I have create notification usingby following http://developer.android.com/wear/notifications/creating.html

Add code for create notification.

// Specify the 'big view' content to display the long
// event description that may not fit the normal content text.
BigTextStyle bigStyle = new NotificationCompat.BigTextStyle();
bigStyle.bigText(eventDescription);

NotificationCompat.Builder notificationBuilder =
        new NotificationCompat.Builder(this)
        .setSmallIcon(R.drawable.ic_event)
        .setLargeIcon(BitmapFractory.decodeResource(
                getResources(), R.drawable.notif_background))
        .setContentTitle(eventTitle)
        .setContentText(eventLocation)
        .setContentIntent(viewPendingIntent)
        .addAction(R.drawable.ic_map,
                getString(R.string.map), mapPendingIntent)
        .setStyle(bigStyle);

Solution 3

That's called Expanded layouts which is available right from Jelly Bean version.

There are 2 views of Notifications:

  1. Normal View
  2. Big View

A notification’s big view appears only when the notification is expanded, which happens when the notification is at the top of the notification drawer, or when the user expands the notification with a gesture. Expanded notifications were first introduced in Android 4.1 JellyBean [API 16].

In your case, you just want to display big picture in notification, give Notification.BigPictureStyle a try:

Bitmap remote_picture = null;

// Create the style object with BigPictureStyle subclass.
NotificationCompat.BigPictureStyle notiStyle = new 
        NotificationCompat.BigPictureStyle();
notiStyle.setBigContentTitle("Big Picture Expanded");
notiStyle.setSummaryText("Nice big picture.");

try {
        remote_picture = BitmapFactory.decodeStream(
                (InputStream) new URL(sample_url).getContent());
} catch (IOException e) {
        e.printStackTrace();
}

// Add the big picture to the style.
notiStyle.bigPicture(remote_picture);
Share:
16,509

Related videos on Youtube

Renjith Krishnan
Author by

Renjith Krishnan

Android Developer My Hobby apps https://play.google.com/store/search?q=Hobynapps

Updated on September 15, 2022

Comments

  • Renjith Krishnan
    Renjith Krishnan over 1 year

    I need to create a custom notification instead of the default notification in android. Current notification have a icon,heading and message like below image

    enter image description here

    I want it customise like this

    enter image description here

    how can i achieve this