O'Reilly logo

Android Application Development by G. Blake Meike, Zigurd Mednieks, John Lombardo, Rick Rogers

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 14. Simple Phone Calls

Android provides the user with several ways of starting phone calls: from the contact list, from the call history, using a dialer that displays a 12-key dialpad on the screen, etc. All of these software modules use the same application to start a phone call. Your program can initiate a phone call in the same way: by using an Intent object to ask Android’s specialized telephony application to make the call. We’ll cover that technique in this chapter, and take a look behind the scenes at how the process works.

In Chapter 15, we’ll introduce Android classes that give you more information about telephony, such as tracking the state of the call you made.

Quick and Easy Phone Calls

Android includes an application called PhoneApp that embodies the functions of a mobile phone. Through the use of Intent objects, Android enables applications to tell other applications to perform certain operations, such as initiating a phone call. To enable your application to initiate a phone call, a method like the one in Example 14-1 will do the job.

Example 14-1. How to make a phone call

private void call() {
    try {
        Intent callIntent = new Intent(Intent.ACTION_CALL);
        callIntent.setData(Uri.parse("tel:9785551212"));
        startActivity(callIntent);
    } catch (ActivityNotFoundException activityException) {
        Log.e("dialing-example", "Call failed", activityException);
    }
}

What happens when you start a phone call depends, in part, on the telephone network. The number may be incorrect. The network ...

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