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.)
Create a new project in Android Studio and call it DialPhone
. Use the default Phone & Tablet option and select Empty Activity when prompted for Activity Type.