Android 以编程方式拨打电话号码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22372561/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android dial a phone number programmatically
提问by Sergo Pasoevi
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 alreadyinput by passing it through the intent, so that she has the option to call that number herself.
如何dial a number
从 Android 应用程序以编程方式?我不想打电话,我知道我可以通过 Intent: 来做new Intent(Intent.ACTION_CALL)
,我只想将用户带到 Android 拨号提示,通过 Intent 传递已经输入的号码,以便她可以选择自己拨打该号码。
回答by Systematix Infotech
Use the below code:
使用以下代码:
Uri number = Uri.parse("tel:123456789");
Intent callIntent = new Intent(Intent.ACTION_DIAL, number);
startActivity(callIntent);
回答by user370305
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.
活动操作:拨打数据指定的号码。这将显示一个带有正在拨打的号码的 UI,允许用户明确发起呼叫。
回答by dipali
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" />
回答by Ahmed Samir
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" />
回答by user7264552
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);
}
});
回答by user9395356
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);