How do I get the dialer to open with phone number displayed?

AndroidAndroid IntentPhone Number

Android Problem Overview


I don't need to call the phone number, I just need the dialer to open with the phone number already displayed. What Intent should I use to achieve this?

Android Solutions


Solution 1 - Android

Two ways to achieve it.

1) Need to start the dialer via code, without user interaction.

You need Action_Dial,

use below code it will open Dialer with number specified

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

The 'tel:' prefix is required, otherwhise the following exception will be thrown: java.lang.IllegalStateException: Could not execute method of the activity.

Action_Dial doesn't require any permission.

If you want to initiate the call directly without user's interaction , You can use action Intent.ACTION_CALL. In this case, you must add the following permission in your AndroidManifest.xml:

<uses-permission android:name="android.permission.CALL_PHONE" />

2) Need user to click on Phone_Number string and start the call.

android:autoLink="phone" 

You need to use TextView with below property.

android:autoLink="phone" android:linksClickable="true" a textView property

You don't need to use intent or to get permission via this way.

Solution 2 - Android

Pretty late on the answer, but if you have a TextView that you're showing the phone number in, then you don't need to deal with intents at all, you can just use the XML attribute android:autoLink="phone" and the OS will automatically initiate an ACTION_DIAL Intent.

Solution 3 - Android

Okay, it is going to be extremely late answer to this question. But here is just one sample if you want to do it in Kotlin.

val intent = Intent(Intent.ACTION_DIAL)
intent.data = Uri.parse("tel:<number>")
startActivity(intent)

Thought it might help someone.

Solution 4 - Android

As @ashishduh mentioned above, using android:autoLink="phone is also a good solution. But this option comes with one drawback, it doesn't work with all phone number lengths. For instance, a phone number of 11 numbers won't work with this option. The solution is to prefix your phone numbers with the country code.

Example:

08034448845 won't work

but +2348034448845 will

Solution 5 - Android

<TextView
 android:id="@+id/phoneNumber"
 android:autoLink="phone"
 android:linksClickable="true"
 android:text="+91 22 2222 2222"
 />

This is how you can open EditText label assigned number on dialer directly.

Solution 6 - Android

You can call Intent following this:

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionNikView Question on Stackoverflow
Solution 1 - AndroidAAnkitView Answer on Stackoverflow
Solution 2 - AndroidashishduhView Answer on Stackoverflow
Solution 3 - AndroidgprathourView Answer on Stackoverflow
Solution 4 - AndroidOjonugwa Jude OchalifuView Answer on Stackoverflow
Solution 5 - Androidsaurabh yadavView Answer on Stackoverflow
Solution 6 - AndroidSubhajit RoyView Answer on Stackoverflow