How to open number dialer pad programmatically in android?

前端 未结 8 653
执笔经年
执笔经年 2021-02-07 04:10

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 keypa

相关标签:
8条回答
  • 2021-02-07 04:17
    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

    0 讨论(0)
  • 2021-02-07 04:24

    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());

    0 讨论(0)
  • 2021-02-07 04:31

    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" />
    
    0 讨论(0)
  • 2021-02-07 04:37
     public void openDialPad(String phoneNumber) {
            Intent intent = new Intent(Intent.ACTION_DIAL);
            intent.setData(Uri.parse(phoneNumber));
            startActivity(intent);
        }
    
    0 讨论(0)
  • 2021-02-07 04:40

    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"
    
    0 讨论(0)
  • 2021-02-07 04:42
    Intent intent = new Intent(Intent.ACTION_DIAL); 
    startActivity(intent); 
    
    0 讨论(0)
提交回复
热议问题