

A PendingIntent simply wraps a regular Intent inside an object such that another application can send the original Intent as if your application had done so. They use the PendingIntent object to do this.

Notifications can trigger an Intent when tapped. Note: While using Notification.Builder may be simpler, it's only available in SDK Level 11 and later. The time (the "when" field) is used to show the user when the notification occurred. The ticker text is displayed briefly in the status bar right when the notification fires. Google has a great resource on creating status bar icons for Android 2.3 and later as well as Android 2.2 and earlier found with the developer documentation icon guidelines. For your own app, it's probably best to create your own set of icons. Here, we set the icon to one of the system icons. UpdateComplete.when = System.currentTimeMillis() UpdateComplete.icon = android.R.drawable.stat_notify_sync Notification updateComplete = new Notification() The notification event, which consists of the specifics to show the user, First, the notification's core data is configured-the icon to be displayed in the status bar, the brief text displayed in the status bar, and the time of the notification are created separate from a notification event. Because existing notifications can be updated, the creation of a notification comes in two parts.

getSystemService(NOTIFICATION_SERVICE) Step 2: Creating a NotificationĪ Notification object encapsulates the information used to display a new notification to a user or to update an existing notification. NotificationManager notificationManager = (NotificationManager) context The following Java code retrieves an instance using the application context:Ĭontext context = TutListDownloaderService.this We'll start by adding code to the onPostExecute() method of the DownloaderTask inner class found in the TustListDownloaderService. Let's start by getting an instance of the NotificationManager object, the base object with which notifications are handled. We will create a simple notification that informs the user when the list of tutorials, in XML format, has been downloaded and parsed. Notifications can also display once, display persistently (for instance, to update the progress of an ongoing task), or display a count of items (for instance, to display the number of new emails). Additionally, notifications can play sounds or flash colorful lights. These details can be drawn in a default way or they can be drawn using a custom RemoveViews object if you want to get fancy. When the status bar is "pulled down", the user can see more notification details. Generally speaking, notifications in the status bar at the top of the users screen (or the bottom on tablets running Android 3.0) appear as an icon and some short text. Instead, we'll focus on getting specific notifications working for the TutList application. This tutorial will not cover every detail of the notification system. It's easy to use, flexible, and convenient. The Android notification system is highly praised by users and developers. The "tags" view of the source viewer has each version, for convenience. You can download that code and work from it, or you can simply download or view the code provided with this tutorial and follow along. This tutorial assumes you start where our last "TutList" tutorial left off. This way, we use notifications to provide feedback to the user that something has happened, while also reminding he user of the existence of the application and that fresh content is available. When the user taps on the notification in the status bar, the application will be launched. In this tutorial, we'll extend the existing unnamed "TutList" application to notify the user when the scheduled download of tutorials has taken place. Luckily, Android has an easy notification system that allows applications to display a message in the status bar and provide informative details to the user when something important occurs. The user won't know what's going on, though, unless they are informed of some event. Often times, applications will perform some background operation-maybe while the app is running or maybe triggered on a scheduled alarm.
