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

Ser*_*evi 27 android android-intent

如何dial a number从Android应用程序进行编程?我不想拨打电话,我知道我可以通过制作一个意图:new Intent(Intent.ACTION_CALL)我只是想让用户进入Android拨号提示,通过传递意图输入已经输入的号码,这样她就可以了可以选择自己拨打该号码.

Sys*_*ech 50

使用以下代码:

Uri number = Uri.parse("tel:123456789");
Intent callIntent = new Intent(Intent.ACTION_DIAL, number);
startActivity(callIntent);
Run Code Online (Sandbox Code Playgroud)

  • 您可以使用此代码从您的活动中提供输入号码,您无法在@ user370305提供的答案中提供拨号号码 (2认同)

use*_*305 10

使用 ACTION_DIAL

喜欢,

Intent intent = new Intent(Intent.ACTION_DIAL);
Run Code Online (Sandbox Code Playgroud)

活动操作:拨打数据指定的号码.这显示了正在拨打号码的UI,允许用户明确发起呼叫.


dip*_*ali 8

Intent intent = new Intent(Intent.ACTION_CALL);

intent.setData(Uri.parse("tel:" + bundle.getString("mobilePhone")));
context.startActivity(intent);
Run Code Online (Sandbox Code Playgroud)

不要忘记向清单添加相关权限:

<uses-permission android:name="android.permission.CALL_PHONE" />
Run Code Online (Sandbox Code Playgroud)