Katerina Zamani

About Katerina Zamani

Katerina has graduated from the Department of Informatics and Telecommunications in National and Kapodistrian University of Athens (NKUA) and she attends MSc courses in Advanced Information Systems at the same department. Currently, her main academic interests focus on web applications, mobile development, software engineering, databases and telecommunications.

Android Make Phone Call Example

Although Android provides Built-in applications for phone calls, in some occasions we may need to make a phone call through our application. This could easily be done by using implicit Intent with appropriate actions. Also, we can use PhoneStateListener and TelephonyManager classes, in order to monitor the changes in some telephony states on the device.

In this tutorial we are going to show how to make a phone call and return back to our activity after it’s end.


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 SDK 4.4

1. Create a New Android Application Project

Open Eclipse IDE and go to File → New → Project → Android Application Project.

Specify the name of the application, the project and the package in the appropriate fields and then click Next.


In the next window, choose the “Create Activity” check-option. The new created activity will be the main activity of your project. Then press Next button.


In “Configure Launcher Icon” window you should choose the icon you want to have in your app. We will use the default icon of android, so press Next button.


Select the “Blank Activity” option and click Next.


Specify a name for the new Activity and a name for the layout description of your app. The .xml file for the layout will automatically be created in the res/layout folder. Finally, press Finish.


Now, you can see the structure of your created project.


2. Create the layout of the Main Activity

In this example we will make a simple user interface. We are going to add an EditText, where the user can fill in the phone number. Moreover, we will put two Buttons where both of them enables a phone call, by using different Intent actions.

Open res/layout/activity_main.xml to the respective xml tab. Then paste the code below.


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    tools:context=".MainActivity" >

        android:hint="Type a number to call..."
        android:inputType="phone" />

        android:text="Call" />
        android:text="Dial and Call" />


3. Code the Main Activity

As we mentioned before, we need an implicit Intent in order to make a phone call from our app. For the action of this Intent we can use ACTION_CALL for a direct call or ACTION_DIAL, where the user can change the phone number before calling. Also, we have to set the data in the Intent by adding the scheme tel: before the phone number.

Although the Intent is sufficient for the phone call, in some cases we want to monitor the phone state. In such situations, we use PhoneStateListener and TelephonyManager classes. In our example we create our own PhoneStateListener, in order to handle some states of the phone call. More specifically, in the state CALL_STATE_IDLE, we want to return to our application’s main activity after the end of the call. For that reason we create a suitable Intent, as you can see in the code below.

Open src/com.javacodegeeks.android.phonecalltest/MainActivity.java file and paste the following.


package com.javacodegeeks.android.phonecalltest;

import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.view.View.OnClickListener;

public class MainActivity extends Activity {

	private Button callBtn;
	private Button dialBtn;
	private EditText number;
	protected void onCreate(Bundle savedInstanceState) {
		number = (EditText) findViewById(R.id.phoneNumber);
		callBtn = (Button) findViewById(R.id.call);
		dialBtn = (Button) findViewById(R.id.dial);

		// add PhoneStateListener for monitoring
		MyPhoneListener phoneListener = new MyPhoneListener();
		TelephonyManager telephonyManager = 
			(TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
		// receive notifications of telephony state changes 
		callBtn.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				try {
					// set the data
					String uri = "tel:"+number.getText().toString();
					Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse(uri));
				}catch(Exception e) {
					Toast.makeText(getApplicationContext(),"Your call has failed...",
		dialBtn.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				try {
					String uri = "tel:"+number.getText().toString();
					Intent dialIntent = new Intent(Intent.ACTION_DIAL, Uri.parse(uri));
				}catch(Exception e) {
					Toast.makeText(getApplicationContext(),"Your call has failed...",
	private class MyPhoneListener extends PhoneStateListener {
		private boolean onCall = false;
		public void onCallStateChanged(int state, String incomingNumber) {
			switch (state) {
			case TelephonyManager.CALL_STATE_RINGING:
				// phone ringing...
				Toast.makeText(MainActivity.this, incomingNumber + " calls you", 
			case TelephonyManager.CALL_STATE_OFFHOOK:
				// one call exists that is dialing, active, or on hold
				Toast.makeText(MainActivity.this, "on call...", 
				//because user answers the incoming call
				onCall = true;

			case TelephonyManager.CALL_STATE_IDLE:
				// in initialization of the class and at the end of phone call 
				// detect flag from CALL_STATE_OFFHOOK
				if (onCall == true) {
					Toast.makeText(MainActivity.this, "restart app after call", 
					// restart our application
					Intent restart = getBaseContext().getPackageManager().
					onCall = false;


4. Set the Permissions

We have to set up the permissions for the completion of the phone call as well as for it’s monitoring. It is good to mention that READ_PHONE_STATE permission is only necessary for the PhoneStateListener.

Open AndroidManifest.xml file, go to the respective xml tab and paste the following.


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    android:versionName="1.0" >

        android:targetSdkVersion="19" />
    <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" />


5. Run the application

To run our application, right click on our project → Run as → Android Application. The AVD will appear with the app loaded.

Fill in a phone number in order to make a call, as shown in the picture below.


Then press “Dial and Call” button. The system leads you to the following screen, in order to change the phone number before the call.


If instead of “Dial and Call” button we click “Call” button, a direct call will launch.


When we end the call, we return back to our application, as shown in the image below. This is happening whichever button we press.


Notice in the pictures above that the appropriate messages, which corresponds to the call states, appear in the suitable cases.

Download Eclipse Project

This was an example of making a phone call in Android. Download the Eclipse Project of this example: PhoneCallTest.zip

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!

1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design

and many more ....

Given email address is already subscribed, thank you!
Oops. Something went wrong. Please try again later.
Please provide a valid email address.
Thank you, your sign-up request was successful! Please check your e-mail inbox.
Please complete the CAPTCHA.
Please fill in the required fields.
Examples Java Code Geeks and all content copyright © 2010-2015, Exelixis Media Ltd | Terms of Use | Privacy Policy | Contact
All trademarks and registered trademarks appearing on Examples Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Examples Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
Do you want to know how to develop your skillset and become a ...
Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

Get ready to Rock!
You can download the complementary eBooks using the links below: