Android Dialing: Call Programs With Touch

To achieve the dialing function in an Android application, you can use Intent to launch the system’s dialer interface and pass the phone number. Here are the steps to implement the dialing function:

  1. Add dialing permission to the AndroidManifest.xml file.
<uses-permission android:name="android.permission.CALL_PHONE" />
  1. To enable the dialing feature, create an Intent object with the Action set to Intent.ACTION_CALL, and include the phone number data.
String phoneNumber = "10086";
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + phoneNumber));
startActivity(intent);
  1. Before launching the dialing interface, it is necessary to check whether dialing permission has been granted. Permission can be checked using the following code:
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
    // 请求拨号权限
    ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CALL_PHONE}, 1);
} else {
    // 已授予拨号权限,启动拨号界面
    startActivity(intent);
}

By following these steps, you can open the dialing interface in an Android application and make a call to a specific phone number.

bannerAds