简体   繁体   English

Android以编程方式拨打电话号码

[英]Android dial a phone number programmatically

How do I dial a number programmatically from the Android application? 如何从Android应用程序dial a number编程方式dial a number 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. 我不想打电话,我知道我可以通过制作一个意图: new Intent(Intent.ACTION_CALL) ,我只是想让用户进入Android拨号提示,通过传递已经输入的号码通过意图,以便她可以选择自己拨打该号码。

Use the below code: 使用以下代码:

Uri number = Uri.parse("tel:123456789");
Intent callIntent = new Intent(Intent.ACTION_DIAL, number);
startActivity(callIntent);

Use ACTION_DIAL 使用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. 这显示了正在拨打号码的UI,允许用户明确发起呼叫。

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" />

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 . url是电话号码,不要忘记在清单文件中写入权限。

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

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM