Placing a call

Print Friendly

This article describes how to make an application to make calls in Android.

Open your manifest.xml and add the following permissions:

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

CALL_PRIVILEGED is optional if you want to call Emergency numbers directly without user intervention (like 911).
Create a class CallPhoneTest that extends Activity. This code is extremely simple, just create an intent with the ACTION_CALL and start the Activity:

public class CallPhoneTest extends Activity {

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.call_phone);
		call();
	}

	private void call() {
		try {
			Intent callIntent = new Intent(Intent.ACTION_CALL);
			callIntent.setData(Uri.parse("tel:911"));
			startActivity(callIntent);
		} catch (ActivityNotFoundException activityException) {
			Toast toast = Toast.makeText(this, "Cannot place a call",
					Toast.LENGTH_SHORT);
			toast.show();
		}
	}
}

And that is it!

Comments are closed.