Chapter 8. Notifications and alarms
This chapter covers
- Building an SMS Notification application
- Working with Toasts
- Working with the NotificationManager
- Using Alarms and the AlarmManager
- Setting an Alarm
Today’s cell phones are expected to be not only phones but personal assistants, cameras, music and video players, and instant-messaging clients, as well as do just about everything else a computer might do. With all these applications running on phones, applications need a way to notify users to get their attention or to take some sort of action, whether in response to an SMS, a new voicemail, or an Alarm reminding them of a new appointment.
In this chapter, we’re going to look at how to use the Android BroadcastReceiver and the AlarmManager to notify users of these sorts of events. First, we’ll look at how to display quick, unobtrusive, and nonpersistent messages called Toasts, based on an event, such as receiving an SMS. Second, we’ll talk about how to create persistent messages, LED flashes, phone vibrations, and other events to alert the user. These events are called Notifications. Finally, we’ll look at how to trigger events by making Alarm events through the AlarmManager. Before we go too deeply into how notifications work, let’s first create a simple example application.