Android Tutorial

(avery) #1

By : Ketan Bhimani


406 

judiciously so as not to unnecessarily disrupt the calling
functionality of the user’s device.

Making Phone Calls

You’ve seen how to find out if the handset is ringing. Now let’s look
at how to enable your application to make phone calls as well.

Building on the previous example, which sent and received SMS
messages, we now walk through similar functionality that adds a
call button to the screen to call the phone number instead of
messaging it.

The Android SDK enables phone numbers to be passed to the dialer
in two different ways. The first way is to launch the dialer with a
phone number already entered. The user then needs to press the
Send button to actually initiate the call. This method does not
require any specific permissions. The second way is to actually
place the call. This method requires the
android.permission.CALL_PHONE
permission to be added to the
application’s AndroidManifest.xml file.

Let’s look at an example of how to enable
an application to take input in the form of
a phone number and launch the Phone
dialer after the user presses a button, as
shown in Figure.

The user can enter a phone number in
the EditText control and press the
Call button to initiate a phone call
from within the application.
Free download pdf