天天看點

android 中打電話,Android 在 APP 中實作撥打電話的方法

Android 在 APP 中實作撥打電話的方法

2020-12-20 09:17:08

方法一:

首先添加撥打電話的權限:

public void callPhone(String phoneNum){

Intent intent = new Intent(Intent.ACTION_CALL);

Uri data = Uri.parse("tel:" + phoneNum);

intent.setData(data);

startActivity(intent);

}

方法二:

public void callPhone(String phoneNum) {

Intent intent = new Intent(Intent.ACTION_DIAL);

Uri data = Uri.parse("tel:" + phoneNum);

intent.setData(data);

startActivity(intent);

}

注意:

第一種方法需要在AndroidMenifest檔案裡加上這個權限:,在Android6.0中,還要在代碼中動态申請權限。

第二種方法不需要申請權限,可以直接跳轉到撥号界面。