with the location for your platform and user account:
• Windows XP: C:Documents and Settings<user>Local SettingsApplication DataAndroid debug.keystore
• Windows Vista: C:Users<user>AppDataLocalAndroiddebug.keystore
(where <user>
is your account name)
The second line of the output contains your MD5 digest, as a series of pairs of hex digits separated by colons.
CHAPTER 35
Handling Telephone Calls
Many, if not most, Android devices will be phones. As such, not only will users be expecting to place and receive calls using Android, but you will have the opportunity to help them place calls, if you wish.
Why might you want to?
• Maybe you are writing an Android interface to a sales management application (a la Salesforce.com
) and you want to offer users the ability to call prospects with a single button click, and without them having to keep those contacts both in your application and in the phone’s contacts application
• Maybe you are writing a social networking application, and the roster of phone numbers that you can access shifts constantly, so rather than try to “sync” the social network contacts with the phone’s contact database, you let people place calls directly from your application
• Maybe you are creating an alternative interface to the existing contacts system, perhaps for users with reduced motor control (e.g., the elderly), sporting big buttons and the like to make it easier for them to place calls
Whatever the reason, Android has the means to let you manipulate the phone just like any other piece of the Android system.
Report to the Manager
To get at much of the phone API, you use the TelephonyManager
. That class lets you do things like:
• Determine if the phone is in use via getCallState()
, with return values of CALL_STATE_IDLE
(phone not in use), CALL_STATE_RINGING
(call requested but still being connected), and CALL_STATE_OFFHOOK
(call in progress)
• Find out the SIM ID (IMSI) via getSubscriberId()
• Find out the phone type (e.g., GSM) via getPhoneType()
or find out the data connection type (e.g., GPRS, EDGE) via getNetworkType()
You Make the Call!
You can also initiate a call from your application, such as from a phone number you obtained through your own Web service. To do this, simply craft an ACTION_DIAL Intent
with a Uri
of the form tel:NNNNN
(where NNNNN
is the phone number to dial) and use that Intent
with startActivity()
. This will not actually dial the phone; rather, it activates the dialer activity, from which the user can then press a button to place the call.
For example, let’s look at the Phone/Dialer
sample application. Here’s the crude-but- effective layout:
<?xml version='1.0' encoding='utf-8'?>
<LinearLayout xmlns:android='http://schemas.android.com/apk/res/android'
android:orientation='vertical'
android:layout_width='fill_parent'
android:layout_height='fill_parent'
>
<LinearLayout
android:orientation='horizontal'
android:layout_width='fill_parent'
android:layout_height='wrap_content'
>
<TextView
android:layout_width='wrap_content'
android:layout_height='wrap_content'
android:text='Number to dial:'
/>
<EditText android:id='@+id/number'
android:layout_width='fill_parent'
android:layout_height='wrap_content'
android:cursorVisible='true'
android:editable='true'
android:singleLine='true'
/>
</LinearLayout>
<Button android:id='@+id/dial'
android:layout_width='fill_parent'
android:layout_height='wrap_content'
android:layout_weight='1'
android:text='Dial It!'
/>
</LinearLayout>
We have a labeled field for typing in a phone number, plus a button for dialing said number.
The Java code simply launches the dialer using the phone number from the field:
package com.commonsware.android.dialer;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class DialerDemo extends Activity {