How to make a phone call

As we've seen in previous recipes, we can call the default applications simply by using an Intent. To make a phone call, use Intent.ACTION_DIAL when creating an Intent. You can include a phone number with the setData() method. Here is sample code that will call up the Dialer app with the phone number specified:

Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:" + number));
startActivity(intent);

Since your application is not doing the dialing and the user must press the Dial button, you do not need any dialing permissions in your app. The following recipe will show you how to place a call directly, bypassing the Dial activity. (For this, you will need to add a permission.)

Getting ready

Create ...

Get Android Application Development Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.