Android Notification Settings: Creating a Simple Android Notification Object

android notification settingsAndroid is the most popular mobile platform in the world today. According to the latest data, more than a million applications have been created for the operating system, with about 25 billion downloads to date. The number of people using Android based smartphones is also growing steadily. Because of this, there is a large demand in the market for Android apps of all kinds, from utility apps to games. This is the best time to learn how to become an Android developer. This Android 101 course is a good place to start.

In this tutorial, we’re going to take a look at how to design and create basic notifications, and the different settings you should use for them. You need to be familiar with the basics of Java to understand this tutorial. If you’re new to it, you may want to first take this basic course for Android.

Android Notifications

Notifications are a great way to keep a user updated with an app’s activity, like a calendar event or an incoming message from a friend. They also help ensure that the user keeps coming back to your app and doesn’t forget about it, whatever your app is.

The notification system in Android is flexible and well designed. You can customize the notifications your app sends out to your user by using the NotificationCompat.Builder object. A typical notification consists of the following things:

  • The Icon/Photo: Your notification should display the icon of your app. If you are developing a messaging app, you might want to change that to show the photo of a sender instead.
  • The Title/Name: Your message should have a title.
  • The Message: This is the most important part of your notification. Your message should be concise and easy to understand, and let the user act on it immediately.
  • The Secondary Icon: The secondary icon can be used to display the icon of your app if you used a photo in the main icon/photo section.
  • The Timestamp: The timestamp shows the time when your notification was sent out.
  • Actions: This is a relatively new feature, introduced in the Jellybean update. Your notification can include an action, like Snooze, at the bottom.

Some of the components of a notification are optional. For a list of what you can skip, check out the official documentation here.

Creating a Simple Notification Object

As we mentioned before, you can create a notification by using the NotificationCompat.Builder object. You call the () method, which will return a Notification object that contains your data. You need to call NotificationManager.notify () to pass the Notification object to the system.

The notification object you are about to define should contain the following things a small icon, tile as well as some textual content. The small icon is set by the setSmallIcon () method, the title is set by the setContenttitle() and the Detail text by the setContentText ().

It’s recommended that you add actions to your notifications, although it’s not mandatory. An Activity (event) is started when a user clicks on the notification, through an action button. This Activity will contain he details of what your application is supposed to do when the user clicks on it.

We’ll show you how to create a simple notification object with the help of some code in the official Android developer application:

NotificationCompat.BuildermBuilder =
 new NotificationCompat.Builder(this)
.setContentTitle("My notification")
.setContentText("Hello World!");
 Intent resultIntent = new Intent(this, ResultActivity.class);
 TaskStackBuilderstackBuilder = TaskStackBuilder.create(this);
 PendingIntentresultPendingIntent =
 NotificationManagermNotificationManager =
 (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

In this example, they’ve created a notification opens when the user clicks on it and allows an activity to be selected. The first part of the program deals with declaring a new object and creating an icon, a title and a message contained in the notification. Declaring an Intent will result in an Activity happening in the program. If the user declines to perform an Activity and backtrack, he will end up on the home screen of the device. This program uses several advanced Java techniques. To learn more about them, we recommend you sign up for our Android development course.

Notification Settings

When you think about notification settings for your Android application, there are several things to consider. It’s a good idea to study the notification system on a few popular applications before creating settings for your own.

The notifications that your application displays should always be controllable by the user. There should also be an option to turn off notifications entirely. A user should get the option to choose how the notification sent out by your application should appear on screen, like with a beeping sound or by activating the user’s ringtone.

Also, you should consider if you want your application to show messages with low priority or just high priority. In Jelly Bean and newer versions of Android, your applications have the ability to display high priority and low priority notifications. Notifications with the highest priority, highlighted by a priority flag, always appear at the top of the heap:

  • Max Priority: Applications that have Max priority show emergency messages and recommend that the user act on them immediately. A normal application, like a game or a office utility app, will normally have no need for max priority.
  • High Priority: High priority notificationsare more common. In a messaging app, they would be used to show a message by an online friend.
  • Default Priority: Default priority notifications will show all notifications that have a medium level of importance.
  • Low Priority: Low priority notifications can be used to remind the user about an impending applications update, or to subscribe for a newsletter.
  • Min Priority: Min priority notifications are those at the bottom of the heap. They will contain unimportant messages or expired events and suggestions.

When creating notifications, try to make that your app sends out important notifications only.  To learn how to design the layout of your notifications and how to add activities to them, you can take this UI design course.  If you’d like help starting off with your Android app design, this course can help you. And while you’re at it, don’t forget to have fun!