How to make a phone call from your Android app

I came across this Android phone dialer tip yesterday. If you want to make a phone call from an Android application, all you have to do is create a new Intent, either an Intent.ACTION_DIAL (to start the call) or Intent.ACTION_CALL (to place the call).

Here are the three lines of source code you need to get started:

Intent dialIntent = new Intent();
dialIntent.setAction(Intent.ACTION_DIAL);
dialIntent.setData(Uri.parse("tel:8675309"));

(You’ll probably need the area code before that number as well.)

Note that Intent.ACTION_DIAL brings up the dialer, but doesn't actually make the phone call. You can replace the second line shown with this line:

dialIntent.setAction(Intent.ACTION_CALL);

and that will place the phone call, but according to the book, Android Recipes, this is discouraged by Google.

To get this recipe to work you'll also have to declare the android.permission.PHONE_CALL permission in your Android manifest file.