Chapter 12. Telephone Applications

12.1. Introduction: Telephone Applications

Ian Darwin

Discussion

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 send and receive SMS (Short Message Service) messages, a.k.a. text messages, assuming your device is telephony-equipped. Nowadays, a great many Android tablets are WiFi-only, and do not have 3G or even 2G telephone/SMS capabilities. For these devices, other capabilities such as SMS via the Internet and VoIP (Voice over IP, usually SIP) have to be used.

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

12.2. 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 12-1 shows the code for the incoming call interceptor, and ...

Get Android Cookbook 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.