Adding Data to an Instance of an Intent

So far, our instance of the Intent class has enough information to tell the Android system we want to start a phone call, but not enough to tell it what number to call.

After creating the Intent instance with the information that means "we want to call a number," in the next line we will add to it the number to call: callIntent.setData(Uri.parse("tel:9785551212"));

Two things happen on this line of code: an instance of a Uri is created, and we use that instance as an argument to the setData method of the Intent class. Step over this line of code, and then let's see what happens to the variables we are inspecting.

Look at the Variable view in Eclipse and you will see that the mData member of this instance of the Intent now refers to the instance of Uri that was returned from the parse method of the Uri class. And if you click on the triangle icon next to "mData", you will see the members of the Uri class, including the uriString member that refers to the string tel:9785551212. Now our instance of the Intent class contains all the information we need to start a phone call.

Why use a URI? All mobile numbers conform to the E.164 standard, so why not use a String object containing a valid E.164 number? A URI has the advantage of generality. All parts of Android are replaceable and the components of Android that handle this particular Intent object could be augmented or replaced by a module that can also connect VoIP calls with SIP URIs or Gmail addresses.

Was this article helpful?

0 0

Post a comment