Using the Dialer

Now that you know what an Intent is, it is time to see one in action. This section shows you how to use the DIAL_ACTION Intent to open the phone dialer. You will pass a telephone number with your Intent. If your application works correctly, you should see displayed in the dialer the number you pass with your Intent.

The first step is to create a new project for this Activity (see Chapter 5 for instructions). Name the project AndroidPhoneDialer. The following illustration shows the New Android Project wizard for this project.

^ N ew An droid P roj e ct

Creates a new Android Project resource.

^^^^ r

Project name: AndroidPhoneDialer ■Contents o Create new project in workspace © Create project from, existing source [V! Use default location

Project name: AndroidPhoneDialer ■Contents o Create new project in workspace © Create project from, existing source [V! Use default location

Location: Ci/Users/JFDiMarzio/workspace/AndroidPhoneDialer Browse,

Properties —

Package name: andro:d_progiammers_guide,AndroidPhoneDialer

Activity name: AndroidPhoneDialer

Application name: AndroidPhoneDialer

© Finish Cancel

With your new application open in Eclipse, the first order of business is to remove the TextView from main.xml that contains that Hello World statement. The main.xml file should look like this after you remove the TextView:

<?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>

You need to add two new packages to your project to utilize the DIAL_ACTION Intent, as follows. The first package allows you to set up Intents and the second allows you to parse URIs.

import android.content.Intent; import android.net.Uri;

0 0

Post a comment