Android Intent call number [duplicate]

徘徊边缘 提交于 2019-12-03 12:36:38

问题


I have my phone number at TextView and want to open "Intent-picker" to choose application that I want to call with(Skype, Viber...) or just dial to call it.

Intent callIntent = new Intent(Intent.ACTION_CALL); calls instantly so it doesn't help me.


回答1:


I think you are looking for something like this:

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

This opens the dialer (or creates a chooser dialog if there are multiple apps installed which can place a phone call) with the number filled in, but does not actually start the call. See this answer for more info.




回答2:


Official Solution

Example intent:

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



回答3:


For kotlin

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


来源:https://stackoverflow.com/questions/34596644/android-intent-call-number

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!