Android意向电话号码

Android Intent call number

我的 phone 号码在 TextView,我想打开 "Intent-picker" 以选择我想使用的应用程序(Skype、Viber...)或直接拨号叫它。

Intent callIntent = new Intent(Intent.ACTION_CALL); 立即调用,所以它对我没有帮助。

我想你正在寻找这样的东西:

Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:0123456789"));
startActivity(intent); 

这会打开拨号器(如果安装了多个可以拨打 phone 电话的应用程序,则会创建一个选择器对话框)并填写号码,但实际上不会开始通话。有关详细信息,请参阅 this answer

官方解决方案

示例意图:

public void dialPhoneNumber(String phoneNumber) {
    Intent intent = new Intent(Intent.ACTION_DIAL);
    intent.setData(Uri.parse("tel:" + phoneNumber));
    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivity(intent);
    }
}

对于科特林

    val intent = Intent(Intent.ACTION_DIAL)
    intent.data = Uri.parse("tel:0123456789")
    startActivity(intent)