This chapter covers

■ Making and receiving phone calls

■ Capturing call-related events

■ Obtaining phone and service information

With an Android device you can surf the web, store and retrieve data locally, access networks, access location information, use many types of applications, and—get this— actually make phone calls.

After all is said and done, one of the most fundamental components of the platform is the mobile phone. Dialing out, receiving calls, sending and receiving text and multimedia messages, and other related telephony services are all available. The added bonus with Android is that all of these items are accessible to developers through simple-to-use APIs and built-in applications that make use of intents and services. You can use the telephony support Android provides quite easily, and you can combine it and embed it in your own applications (as you have seen in previous examples).

In this chapter we will examine a bit of telephony background and cover terms involved with a mobile device. We will move on to basic Android telephony packages, which will take us through handling calls using built-in Intent actions and

examining the TelephonyManager and PhoneStateListener classes. The Intent actions are what you will use on a day-to-day basis to initiate phone calls in your applications. TelephonyManager is, on the other hand, not related to making calls but rather is used to retrieve all kinds of telephony-related data, such as the state of the voice network, the device's own phone number, and Subscriber Identity Module (SIM) card details. Using TelephonyManager is also how you attach a PhoneStateListener, which can alert you when call or phone network states change.

Once we have basic telephony APIs in hand, we will move on to working with another very common mobile phone feature—sending and receiving SMS messages. Android provides intents and built-in applications for handling SMS messages as well as APIs that allow you to send SMS messages and be notified when SMS messages are received.

We will also touch on emulator features that allow you to send in test calls and/or messages to exercise your applications.

We are once again going to use a sample application to carry us through the concepts related to the material in this chapter. We will be building a TelephonyExplorer application to demonstrate dialing the phone, obtaining phone and service state information, adding listeners to the phone state, and working with SMS. Our TelephonyExplorer application will have several basic screens, as shown in figure 7.1.

Figure 7.1 TelephonyExplorer main screen, showing all the related activities the sample application performs

TelephonyExplorer, as you can see from the screen shot, is not pretty, nor is it very practical outside of learning the concepts and API details involved. This application is focused on touching the telephony-related APIs while remaining simple and uncluttered.

Before we begin to build TelephonyExplorer, the first thing we first need to clarify what telephony is and learn the terminology.

0 0

Post a comment