android-Two ways to make phone calls in android programmatically

1. The purpose of this post

This post would demo two simple ways to make phone calls in android programmatically.

2. Environments

  • android 4+

3. The code

Before start ,you must add permission requirement to your AndroidManifest.xml

<uses-permission android:name="android.permission.CALL_PHONE" />

3.1 Way 1: The semiautomatic way

The semiautomatic way is as follows, it only popup a window and users must click to make the phone call.

public void callPhone(String phoneNum) {
    Intent intent = new Intent(Intent.ACTION_DIAL); //Would popup a window, user must click dial to make phone call

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

    startActivity(intent);

3.2 Way 2: The automatic way

The semiautomatic way is as follows, it only popup a window and users must click to make the phone call.

public void callPhone(String phoneNum) {
    Intent intent = new Intent(Intent.ACTION_CALL); //Would make phone call automatically.

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

    startActivity(intent);

-->