Android: How to make a phone call

A very useful feature in Android is that  you can use the built in Android Application to make phone calls from inside the Application. You can also use the  TelephonyManager and a PhoneStateListener in order to monitor the phone state.

For this tutorial, we will use the following tools in a Windows 64-bit platform:

  1. JDK 1.7
  2. Eclipse 4.2 Juno
  3. Android SKD 4.2

1. Create a new Android Project

Open Eclipse IDE and go to File -> New -> Project -> Android -> Android Application Project and click Next.

You have to specify the Application Name, the Project Name and the Package name in the appropriate text fields and then click Next.

In the next window make sure the “Create activity” option is selected in order to create a new activity for your project, and click Next. This is optional as you can create a new activity after creating the project, but you can do it all in one step.

Select “BlankActivity” and click Next.

You will be asked to specify some information about the new activity.  In the Layout Name text field you have to specify the name of the file that will contain the layout description of your app. In our case the file res/layout/main.xml will be created. Then, click Finish.

2. Create the main Layout of the Application

Open res/layout/main.xml file :

And paste the following code :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
    android:orientation="vertical" >

        android:text="Call 123456" />


3. Set Permissions in AndroidManifest.xml

Go to AndroidManifest.xml

And paste the following code in order to set the appropriate permission for the Application:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
    android:versionName="1.0" >

        android:targetSdkVersion="16" />

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

        android:theme="@style/AppTheme" >
            android:label="@string/app_name" >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />


In the above code we have set up the permission to make a phone call from our Application as well as the permission to monitor the phone state with the lines below:

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

4. Code

Go to the java file that contains the code of the activity you’ve just created:

And paste the following code:


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {

	final Context context = this;
	private Button btn;

	public void onCreate(Bundle savedInstanceState) {


		btn = (Button) findViewById(;

		PhoneCallListener phoneCallListener = new PhoneCallListener();
		TelephonyManager telManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
		telManager.listen(phoneCallListener, PhoneStateListener.LISTEN_CALL_STATE);

		// add button listener
		btn.setOnClickListener(new OnClickListener() {

			public void onClick(View view) {

				Intent phoneCallIntent = new Intent(Intent.ACTION_CALL);




	// monitor phone call states
	private class PhoneCallListener extends PhoneStateListener {


		private boolean phoneCalling = false;

		public void onCallStateChanged(int state, String incomingNumber) {

			if (TelephonyManager.CALL_STATE_RINGING == state) {
				// phone ringing
				Log.i(TAG, "RINGING, number: " + incomingNumber);

			if (TelephonyManager.CALL_STATE_OFFHOOK == state) {
				// active
				Log.i(TAG, "OFFHOOK");

				phoneCalling = true;

			// When the call ends launch the main activity again
			if (TelephonyManager.CALL_STATE_IDLE == state) {

				Log.i(TAG, "IDLE");

				if (phoneCalling) {

					Log.i(TAG, "restart app");

					// restart app
					Intent i = getBaseContext().getPackageManager()


					phoneCalling = false;



Let’s take a closer look to the above code. Notice that when we press the button the built in phone Application launches:

Intent phoneCallIntent = new Intent(Intent.ACTION_CALL);

We also take the TelephonyManager of our Application with : this.getSystemService(Context.TELEPHONY_SERVICE) and we register a PhoneStateListener to it in order to monitor the phone state. Now the PhoneStateListener will leave log messages in LogCat that reflect the state of the phone. When a call ends the main Activity of the Application launches again.

5. Run the application

This is the main screen of our Application:

When you tap in the button the built in phone Application launches:

Now when you cancel the call, the main Activity of our Application will be launched again so we will go back to the main screen.

Download Eclipse Project

This was an Android Phone Call Example. Download the Eclipse Project of the first part of this tutorial:

Byron Kiourtzoglou

Byron is a master software engineer working in the IT and Telecom domains. He is an applications developer in a wide variety of applications/services. He is currently acting as the team leader and technical architect for a proprietary service creation and integration platform for both the IT and Telecom industries in addition to a in-house big data real-time analytics solution. He is always fascinated by SOA, middleware services and mobile development. Byron is co-founder and Executive Editor at Java Code Geeks.
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments
Back to top button