ptg7068951
Designing a Real App 365
Here are the three Intents employed in this method:
action = new Intent(Intent.ACTION_DIAL, Uri.parse(“tel:202-456-1111”));
action = newIntent(Intent.ACTION_VIEW,
➥Uri.parse(“http://whitehouse.gov”));
action = new Intent(Intent.ACTION_VIEW, Uri.parse(“geo:0,0?q=White House,
➥ Washington, DC”));
The Intent()constructor takes two arguments:
. The action to take, represented by one of its class variables
. The data associated with the action
These three Intents tellthe Android device to set up an outgoing phone call
to the White House public phone line at (202) 456-1111, visit the website
http://whitehouse.gov, and load Google Maps with the partial address
“White House, Washington, DC,” respectively.
After you have created an Intent, the following statement makes it do some-
thing:
startActivity(action);
The full text of the LeaderActivityclass is in Listing 24.2. Add the import
statements in lines 3–8 and the processClicks()method to what you
already have entered. Make sure your code matches the entire listing.
LISTING 24.2 The Full Text of LeaderActivity.java
1: packageorg.cadenhead.android;
2:
3: importandroid.app.Activity;
4: importandroid.content.Intent;
5: importandroid.net.Uri;
6: importandroid.os.Bundle;
7: importandroid.util.Log;
8: importandroid.view.View;
9:
10: public classLeaderActivity extendsActivity {
11: public static finalString TAG = “Leader”;
12:
13: /* Called when the activity is first created. /
14: @Override
15: public voidonCreate(Bundle savedInstanceState) {
16: super.onCreate(savedInstanceState);
17: setContentView(R.layout.main);
18: }
19: