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.
Related Whitepaper:

Rapid Android Development: Build Rich, Sensor-Based Applications with Processing

Create mobile apps for Android phones and tablets faster and more easily than you ever imagined

Use 'Processing', the free, award-winning, graphics-savvy language and development environment, to work with the touchscreens, hardware sensors, cameras, network transceivers, and other devices and software in the latest Android phones and tablets.

Get it Now!  

Leave a Reply


six × 5 =



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use
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.

Sign up for our Newsletter

15,153 insiders are already enjoying weekly updates and complimentary whitepapers! Join them now to gain exclusive access to the latest news in the Java world, as well as insights about Android, Scala, Groovy and other related technologies.

As an extra bonus, by joining you will get our brand new e-books, published by Java Code Geeks and their JCG partners for your reading pleasure! Enter your info and stay on top of things,

  • Fresh trends
  • Cases and examples
  • Research and insights
  • Two complimentary e-books