There are several different Intent Filters on the DIAL_ACTION Intent that you can use. You are using the Filter that lets you pass a phone number as a URI.

The next step is to create your Intent. The syntax for creating an Intent is as follows:

Intent <intent_name> = new Intent(<Android_Intent>,<data>)

For your application, replace the first parameter, <intent_name>, with DialIntent. To get the value for the second parameter, <Android_Intent>, refer to the list of Activity Actions in Table 7-1. You'll find that, to call the dialer, you need to use the DIAL_ACTION Intent. To call the Intent properly, use the format Intent.DIAL_ ACTION. The last parameter, <data>, is the phone number. The DIAL_ACTION Intent takes in data as a URI. Thus, you need to use Uri.parse to parse out your phone number. Using Uri.parse will ensure that the DIAL_ACTION Intent understands the number you are trying to dial. You pass Uri.parse a string that represents the phone number you want to dial, "tel:5551212" in this example.

The final call to create an Intent for your project should look like this:

Intent DialIntent = new Intent(Intent.DIAL_ACTION,Uri. parse("tel:5551212"));

0 0

Post a comment