Since Google released Android Honeycomb, the framework team has continued to work at making notifications useful and a thing of beauty. Google’s latest and greatest foray into the world of smartphone operating systems, Jelly Bean, provides the most feature rich API for status notifications yet. Using the notification builder class, you can create impressive notifications that support intents, images, and previews all in a few lines of code. In this tutorial, we will do just that.

In order for the code to compile and run, you will need to update your SDK and your ADT plug-in (if you haven’t done so already) to Android 4.1 (API 16). I upgraded both from within Eclipse Indigo without any hiccups. Once your environment is ready, you can follow along with the walkthrough, or simply download and import the project.

1. Create a new Android project in Eclipse. Make sure to target Android 4.1. Rename the startup file to

2. In your /res directory, add a new folder called drawable. Here you can place any PNG image and call it avatar.png. While the code scales the image to the system-defined size for the notification dialog, try to use something square so as not to lose the aspect ratio. My image is 255×255 pixels.

3. For this example, we don’t have any reason to modify the default layout, so let’s skip straight to the /src/ file.
package com.authorwjf.e_notifications;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
public class Main extends Activity {
public void onCreate(Bundle savedInstanceState) {
Bitmap bm = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.avatar),
Intent intent = new Intent(this, Main.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 01, intent, Intent.FLAG_ACTIVITY_CLEAR_TASK);
Notification.Builder builder = new Notification.Builder(getApplicationContext());
builder.setContentTitle("This is the title");
builder.setContentText("This is the text");
builder.setSubText("Some sub text");
builder.setTicker("Fancy Notification");
Notification notification =;
NotificationManager notificationManger =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManger.notify(01, notification);

As you can see, thanks to the Notification.Builder helper, there isn’t a lot to be done. Utilizing the default template, we can add things like icons, a count, and the subtext for a lengthy preview of content. It’s straightforward and a lot of bang for your buck (Figure A).
Figure A

In my mind, it is the incremental releases like Jelly Bean that really helps to narrow any gap that still exists between Android and iOS. What do you think of Google’s latest SDK? Sound off in the comments.