Android Programming Tutorials

(Romina) #1
Asking Permission to Place a Call

Figure 61. The Dialer

Step #7: Make the Call.......................................................................


Suppose we want to take advantage of the CALL_PHONE permission we


requested earlier in this tutorial. All that we need to do is switch our Intent


from ACTION_DIAL to ACTION_CALL:


@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId()==R.id.call) {
String toDial="tel:"+phone.getText().toString();

if (toDial.length()> 4 ) {
startActivity(new Intent(Intent.ACTION_CALL,
Uri.parse(toDial)));

return(true);
}
}

return(super.onOptionsItemSelected(item));
}

346
Free download pdf