About Javier Manzano

Javier is an Android and node.js developer. Working day to day on new pet projects. Founder of Parkuik and Codeely.

Android – Using Jelly Bean notifications

Last post was long ago! I’ve been very busy lately… but learning a lot from Android! (and Node js too… I’m in love with this platform!)
Other things that I decided for those who are following me is that, since now, articles will only be in English (sorry =/ ) and all the source code of my examples will be available on github.
Obviously, being an Android developer, Google I/O has been a great source of new things to learn… And one of the was Jelly Bean (Android 4.1 for those that don’t know it yet).
One of the top new things Jelly Bean brings us is new notification functionalities. You can see them in the Google I/O Keynote or some of the articles all over the Internet (1, 2, 3, 4)
So, Where do we have to begin? First of all, you’ll have to create an Android Project with Jelly Bean SDK version.
Probably, most of you had used NotificationManager to push notifications on Android devices… For new Jelly Bean notifications it must be used almost in the same way. You can use something like this:
NotificationManager notificationManager = getNotificationManager();
Notification notification =
     new Notification(android.R.drawable.ic_menu_camera, "Hello camera!", System.currentTimeMillis());
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.number += 1;

Intent intent = new Intent(this, MainActivity.class);
PendingIntent activity = PendingIntent.getActivity(this, 0, intent, 0);
notification.setLatestEventInfo(this, "title", "content", activity);

notificationManager.notify(0, notification);
What do we have to do to use new Jelly Bean notifications? It’s pretty easy…. and I must admit that I prefer this way using the Builder pattern. This is an example of the Big picture style:
Builder build = new Notification.Builder(this)
   .setContentTitle("New mail from me")
   .setContentText("subject")
   .setTicker("New email with photo")
   .setSmallIcon(R.drawable.ic_action_search)
   .addAction(
    android.R.drawable.ic_btn_speak_now,
    "Speak!",
    PendingIntent.getActivity(getApplicationContext(), 0,
     getIntent(), 0, null))
   .addAction(
    android.R.drawable.ic_dialog_map,
    "Maps",
    PendingIntent.getActivity(getApplicationContext(), 0,
     getIntent(), 0, null))
   .addAction(
    android.R.drawable.ic_dialog_info,
    "Info",
    PendingIntent.getActivity(getApplicationContext(), 0,
     getIntent(), 0, null));

Notification notification = new Notification.BigPictureStyle(build)
    .bigPicture(
      BitmapFactory.decodeResource(getResources(),
        R.drawable.jellybean)).build();

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

notificationManager.notify(0, notification);
All the code is available at my github account (where you can find the beggining of a new ORM solution for Android which I hope someday will be finished =/) on the following link. you can find in that project other example of the new notifications too (inbox style and big text).
Here is how the three notifications will show up in your Android devices…. (if you have Jelly Bean on them :-P )
I hope you like the article, and you can ask me any doubt, follow me on twitter or write me and email.
Reference: Using Jelly Bean notifications from our JCG partner Javier Manzano at the Javier Manzano’s Blog blog.

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

JPA Mini Book

Learn how to leverage the power of JPA in order to create robust and flexible Java applications. With this Mini Book, you will get introduced to JPA and smoothly transition to more advanced concepts.

JVM Troubleshooting Guide

The Java virtual machine is really the foundation of any Java EE platform. Learn how to master it with this advanced guide!

Given email address is already subscribed, thank you!
Oops. Something went wrong. Please try again later.
Please provide a valid email address.
Thank you, your sign-up request was successful! Please check your e-mail inbox.
Please complete the CAPTCHA.
Please fill in the required fields.

Leave a Reply


4 − three =



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy | Contact
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
Do you want to know how to develop your skillset and become a ...
Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

Get ready to Rock!
You can download the complementary eBooks using the links below:
Close