Android dial a phone number programmatically

2020-05-29 19:53发布

How do I dial a number programmatically from the Android application? I don't want to make a call, which I know I can do by making an intent: new Intent(Intent.ACTION_CALL), I just want to take the user to the Android dial prompt, with the number already input by passing it through the intent, so that she has the option to call that number herself.

6条回答
我命由我不由天
2楼-- · 2020-05-29 20:20

Use ACTION_DIAL

Like,

Intent intent = new Intent(Intent.ACTION_DIAL);

Activity Action: Dial a number as specified by the data. This shows a UI with the number being dialed, allowing the user to explicitly initiate the call.

查看更多
Summer. ? 凉城
3楼-- · 2020-05-29 20:23

This code will make a call without user interaction and will also pick up the default phone dialler

    Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + url));
    intent.setClassName("com.android.phone","com.android.phone.OutgoingCallBroadcaster");
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(intent);

IF you wants the user to choose his dialler remove

intent.setClassName("com.android.phone","com.android.phone.OutgoingCallBroadcaster");

If you want just to throw the number to the dialler and the user press the call button use this code (I believe thats what you are asking for )

    Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + url));
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(intent);

Where the url is the phone number and dont forget to write the permission in the manifest file .

    <uses-permission android:name="android.permission.CALL_PHONE" />
查看更多
Juvenile、少年°
4楼-- · 2020-05-29 20:23

I had a similar problem which was solved by

        btn.setOnClickListener(new  View.OnClickListener(){
        public void onClick(View v) {
            String q=(t.getText().toString());
            Uri u=Uri.parse("tel:"+q);

            Intent i=new Intent(Intent.ACTION_VIEW,u);
            startActivity(i);
        }
    });
查看更多
叛逆
5楼-- · 2020-05-29 20:39
Intent intent = new Intent(Intent.ACTION_CALL);

intent.setData(Uri.parse("tel:" + bundle.getString("mobilePhone")));
context.startActivity(intent);

Don't forget to add the relevant permission to your manifest:

<uses-permission android:name="android.permission.CALL_PHONE" />
查看更多
Viruses.
6楼-- · 2020-05-29 20:40

Use the below code:

Uri number = Uri.parse("tel:123456789");
Intent callIntent = new Intent(Intent.ACTION_DIAL, number);
startActivity(callIntent);
查看更多
▲ chillily
7楼-- · 2020-05-29 20:43

This code will dial your number without mobile phones default calling keypad:

Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + textView.getText())); 
intent.setClassName("com.android.phone","com.android.phone.OutgoingCallBroadcaster");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
查看更多
登录 后发表回答