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 ...

Get Android Cookbook, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.