O'Reilly logo

Android Cookbook, 2nd Edition by Ian F. Darwin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 11. Telephone Applications

Android began as a platform for cellular telephone handsets, so it is no surprise that Android apps are very capable of dealing with the phone. You can write apps that dial the phone, or that guide the user to do so. You can write apps that verify or modify the number the user is calling (e.g., to add a long-distance dialing prefix). You can also write apps that send and receive SMS (Short Message Service) messages, a.k.a. text messages, assuming the device is telephony-equipped. Nowadays, a great many Android tablets are WiFi-only, and do not have 4G, 3G, or even 2G telephone/SMS capabilities. For these devices, other capabilities such as SMS via internet and VoIP (Voice over IP, usually using SIP) have to be used.

This chapter covers most of these topics; a few are discussed elsewhere in this book.

11.1 Doing Something When the Phone Rings

Johan Pelgrim

Problem

You want to act on an incoming phone call and do something with the incoming number.

Solution

You can implement a broadcast receiver and then listen for a TelephonyManager.ACTION_PHONE_STATE_CHANGED action.

Discussion

If you want to do something when the phone rings you have to implement a broadcast receiver, which listens for the TelephonyManager.ACTION_PHONE_STATE_CHANGED Intent action. This is a broadcast Intent action indicating that the call state (cellular) on the device has changed. Example 11-1 shows the code for the incoming call interceptor, and Example 11-2 shows the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required