21

I want to display Number Dial Keypad (Phone Call) Programmatically on button click in android. Code is available for direct number dialing but I only need to show the dial keypad when I click the Button.

ppeterka
  • 20,583
  • 6
  • 63
  • 78
Addon_Android
  • 271
  • 1
  • 2
  • 9

9 Answers9

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

For this we don't need to add any permission in AndroidManifest.xml

Thamilan S
  • 1,045
  • 3
  • 18
  • 30
Kishore Kumar
  • 616
  • 5
  • 3
28

You can use this code if you want to open the dialer programmatically without any number inserted:

Java

Intent intent = new Intent(Intent.ACTION_DIAL);
startActivity(intent);

Kotlin

val intent = Intent(Intent.ACTION_DIAL)
startActivity(intent)

If you need to open the dialer with the number already digited you can use this code:

Java

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

Kotlin

val intent = Intent(Intent.ACTION_DIAL)
intent.data = Uri.parse("tel:123 456789")
startActivity(intent)
lpizzinidev
  • 12,741
  • 2
  • 10
  • 29
MrYanDao
  • 1,253
  • 1
  • 15
  • 27
4
Intent intent =  new Intent(Intent.ACTION_CALL_BUTTON);
startActivity(intent);

it will show Dial Window check here for information

Jared Burrows
  • 54,294
  • 25
  • 151
  • 185
Just Variable
  • 892
  • 10
  • 19
3

Make button or any widget example : button1

  button1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent callIntent = new Intent(Intent.ACTION_DIAL);
            callIntent.setData(Uri.parse("tel:"+button1.getText().toString().trim()));
            startActivity(callIntent);

        }
    });

Add permission in manifest :

 <uses-permission android:name="android.permission.CALL_PHONE" />
Hanisha
  • 849
  • 10
  • 8
2
 public void openDialPad(String phoneNumber) {
        Intent intent = new Intent(Intent.ACTION_DIAL);
        intent.setData(Uri.parse(phoneNumber));
        startActivity(intent);
    }
1
Intent callIntent = new Intent(Intent.ACTION_DIAL);
callIntent.setData(Uri.parse("tel:" + phoneNumber));
 if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
                // TODO: Consider calling
                //    ActivityCompat#requestPermissions
                // here to request the missing permissions, and then overriding
                //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
                //                                          int[] grantResults)
                // to handle the case where the user grants the permission. See the documentation
                // for ActivityCompat#requestPermissions for more details.
                return;
            }
startActivity(callIntent);

Also, you should register the custom dialscreen as follows in the manifest:

<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
    android:name=".MyDialerApplication"
    android:label="@string/app_name" >

    <intent-filter android:priority="100" >
        <action android:name="android.intent.action.MAIN" />
         <action android:name="android.intent.action.DIAL" />
         <action android:name="android.intent.action.CALL_PRIVILEGED" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:scheme="tel" />

    </intent-filter>
</activity>

Vinitha Edwin
  • 93
  • 1
  • 11
0

If you want to use it in non activity class then create a function like this :

package bp;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;

import session.MyApplication;

/**
 * Created by Atiar Talukdar on 7/11/2019.
 */
public class Utils {

    public static void openDialPad(Activity activity, String phoneNumber) {
        Intent intent = new Intent(Intent.ACTION_DIAL);
        intent.setData(Uri.parse("tel:" + phoneNumber));
        activity.startActivity(intent);
    }
}

and then call from anywhare in like :

Utils.openDialPad(getActivity(),data.getContactNo());

or

Utils.openDialPad(this,data.getContactNo());

Atiar Talukdar
  • 668
  • 11
  • 22
0

This is different, but if you want to access your dialer pad by clicking a number, in your xml, declare the autolink attribute

android:autoLink="phone"
Roshan S
  • 667
  • 6
  • 10
0

Simplest code for opening dialer with given mobile number :

val intent = Intent(Intent.ACTION_DIAL,Uri.parse("tel:$text"))
startActivity(intent)
Elikill58
  • 4,050
  • 24
  • 23
  • 45