How to Make Calls and Use SMS in Android Apps

How to Make Calls and Use SMS in Android Apps

In this tutorial, you’ll learn about the Android Telephony and SMS API. You’ll learn how to make a call from your app and how to monitor phone call events, as well as how to send and receive SMS.

1. How to Make A Call

To start off, I’ll show you how to initiate a call from your application either by using the phone dialer app or directly from your app to make it easier for your users.

Create a New Android Studio Project

Fire up Android Studio and create a new project with an empty activity called MainActivity

Lay Out the Screen

For now, our layout will just have an EditText field and a Dial button:

<?xml version="1.0" encoding="utf-8"?>
            android:hint="Enter Phone number"


Modify the MainActivity Class

In the code block below, we are creating an ACTION_DIAL intent to display the phone dialer. The phone number is parsed from our tel URI scheme: tel:XXXXXXXX. Note that you don’t need any permission for this to work:import android.content.Intent;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
    protected void onCreate(Bundle savedInstanceState) {
        Button mDialButton = (Button) findViewById(;
        final EditText mPhoneNoEt = (EditText) findViewById(;
        mDialButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                String phoneNo = mPhoneNoEt.getText().toString();
                if(!TextUtils.isEmpty(phoneNo)) {
                    String dial = "tel:" + phoneNo;
                    startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse(dial)));
                }else {
                    Toast.makeText(MainActivity.this, "Enter a phone number", Toast.LENGTH_SHORT).show();

If you run the app and click the dial button, you’ll be taken to the dialer app, and from there you have to actually dial the number. You can change this flow to actually make the call from within your app by simply changing the ACTION_DIAL intent to ACTION_CALL instead. This will require the android.permission.CALL_PHONE permission, though.

Continue to read the full article on Tuts+.