Android Call Managing App – Say Goodbye to Call Chaos
We offer you a brighter future with FREE online courses - Start Now!!
In today’s fast-paced world, it’s not uncommon to miss calls due to various reasons. However, it’s also essential to stay connected with our contacts, and one way to do that is by sending them an SMS when we miss their call.
In this project, we’ll be building an Android Call Managing App using Java that sends an SMS to the caller when a user doesn’t pick up calls, i.e., missed calls.
About Android Call Managing App
The main objective of this project is to help you understand how to build a basic Android app that manages missed calls and sends an SMS to the caller. By the end of this project, you will have a functioning app that can be used to stay connected with your contacts even if you miss their calls.
Prerequisites for Call Managing App using Android
To follow along with this project, you’ll need to have some knowledge of Java and Android app development. You should also have Android Studio installed on your computer, which you can download from the official Android Studio website.
Additionally, you should have a basic understanding of XML and Android layouts.
Download Android Call Managing App Project
Please download the source code of Android Call Managing App Project: Android Call Managing App Project Code
Steps to Create Call Managing App Project using Android
Following are the steps for developing the Android Call Managing App Project:
Creating Layout: activity_main.xml
In this step we will create the layout of the app using Buttons to stop and start the service, editText field to take the message from the user to send to the callers and TextView to label the fields.
Code: activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:background="@drawable/gradiant" tools:context=".MainActivity"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginStart="50dp" android:layout_marginTop="50dp" android:layout_marginEnd="50dp" android:layout_marginBottom="50dp" android:gravity="center" android:text="Auto Reply App" android:textSize="40dp" android:id="@+id/textView" android:textStyle="bold" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/textView" android:layout_marginStart="20dp" android:layout_marginTop="15dp" android:layout_marginEnd="20dp" android:layout_marginBottom="20dp" android:textStyle="bold" android:gravity="left" android:id="@+id/textView2" android:text="Enter your message" android:textSize="20dp" /> <com.google.android.material.textfield.TextInputLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/textView2" android:layout_marginStart="20dp" android:layout_marginEnd="20dp" android:hint="Enter your message" android:id="@+id/message"> <com.google.android.material.textfield.TextInputEditText android:id="@+id/textInputEditText" android:layout_width="match_parent" android:layout_height="match_parent" android:inputType="text" android:lines="5" /> </com.google.android.material.textfield.TextInputLayout> <com.google.android.material.textfield.TextInputLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/message" android:layout_marginStart="20dp" android:layout_marginEnd="20dp" android:hint="Enter time in minutes" android:id="@+id/time"/> <Button android:layout_width="match_parent" android:layout_height="60dp" android:layout_below="@+id/time" android:layout_marginStart="20dp" android:layout_marginTop="60dp" android:layout_marginEnd="20dp" android:layout_marginBottom="20dp" android:text="Start" android:id="@+id/start" android:backgroundTint="#66BB6A" android:textColor="#ffffff" android:textSize="20dp" /> <Button android:layout_width="match_parent" android:layout_height="60dp" android:layout_below="@+id/start" android:layout_marginStart="20dp" android:layout_marginTop="5dp" android:layout_marginEnd="20dp" android:layout_marginBottom="20dp" android:text="Stop" android:id="@+id/stop" android:backgroundTint="#EF5350" android:textColor="#ffffff" android:textSize="20dp" /> </RelativeLayout>
Handling layout using MainActivity.java
In this code, we have:
- Defined two Button objects, start and stop, and an EditText object, message, which are linked to the corresponding UI elements in the activity_main.xml file using their IDs.
- Created a BroadcastReceiver callReceiver to handle incoming calls and send an auto-reply SMS if the call is missed.
- Overridden the onCreate() method to set up the UI and button click listeners, as well as to check if the necessary permissions have been granted.
- Defined a checkPermissions() method to check if the necessary permissions have been granted, and a requestPermissions() method to request them if they have not.
- Defined a startAutoReplyService() method to register the callReceiver and start the auto-reply service when the start button is clicked.
- Defined a stopAutoReplyService() method to unregister the callReceiver and stop the auto-reply service when the stop button is clicked.
- Defined a sendAutoReplySMS() method to send an auto-reply SMS to the missed call number, using the message entered in the messageEditText.
- Overridden the onRequestPermissionsResult() method to handle the result of the permission request, and to start the auto-reply service if all permissions are granted.
- Overridden the onDestroy() method to unregister the callReceiver when the activity is destroyed.
Code: MainActivity.java
// Importing the required libraries package com.projectgurukul.androidcallmanagingapp; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.pm.PackageManager; import android.os.Bundle; import android.telephony.SmsManager; import android.telephony.TelephonyManager; import android.util.Log; import android.widget.Button; import android.widget.Toast; import com.google.android.material.textfield.TextInputLayout; import java.util.ArrayList; // Create a class MainActivity which extends AppCompatActivity public class MainActivity extends AppCompatActivity { // Declare the required variables private Button start, stop; private TextInputLayout message; // Creating a TAG for logging private static final String TAG = "MainActivity"; // Creating a constant for the permission request private static final int REQUEST_CODE_PERMISSIONS = 123; // Creating a BroadcastReceiver for the incoming calls // This will be called when the phone receives an incoming call // It will check if the phone number is not null and then send an SMS private BroadcastReceiver callReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE); String phoneNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER); if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) { Log.d(TAG, "Incoming call from: " + phoneNumber); if (phoneNumber != null) { sendAutoReplySMS(phoneNumber); } else { Log.w(TAG, "Phone number is null"); } } } }; // Creating a onCreate method which will be called when the app is launched @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Initializing the variables start = findViewById(R.id.start); stop = findViewById(R.id.stop); message = findViewById(R.id.message); // Setting the onClickListener for the start button // It will check if the message is empty or not start.setOnClickListener(v -> { if(message.getEditText().getText().toString().isEmpty()) { message.setError("Please enter a message"); } else { message.setError(null); // If the message is not empty, it will start the service startAutoReplyService(); } }); // Setting the onClickListener for the stop button stop.setOnClickListener(v -> { // It will stop the service stopAutoReplyService(); }); // Checking if the permissions are granted or not if (!checkPermissions()) { // If the permissions are not granted, it will request for the permissions requestPermissions(); } } // Creating a method to check if the permissions are granted or not private boolean checkPermissions() { return ContextCompat.checkSelfPermission(this, android.Manifest.permission.SEND_SMS) == PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(this, android.Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(this, android.Manifest.permission.READ_CALL_LOG) == PackageManager.PERMISSION_GRANTED; } // Creating a method to request for the permissions if they are not granted private void requestPermissions() { ActivityCompat.requestPermissions(this, new String[]{ android.Manifest.permission.SEND_SMS, android.Manifest.permission.READ_PHONE_STATE, android.Manifest.permission.READ_CALL_LOG, }, REQUEST_CODE_PERMISSIONS); } // Creating a method to start the Auto Reply service // It will check if permissions are granted, and then register the callReceiver variable private void startAutoReplyService() { if (checkPermissions()) { registerReceiver(callReceiver, new IntentFilter(TelephonyManager.ACTION_PHONE_STATE_CHANGED)); Toast.makeText(this, "Auto-reply service started", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(this, "Please grant the necessary permissions first", Toast.LENGTH_SHORT).show(); } } // Creating a method to stop the Auto Reply service // It will unregister the callReceiver to stop listening for the incoming calls private void stopAutoReplyService() { unregisterReceiver(callReceiver); Toast.makeText(this, "Auto-reply service stopped", Toast.LENGTH_SHORT).show(); } // Creating a method to reply to the missed calls using SMS private void sendAutoReplySMS(String phoneNumber) { //Parsing message from the EditText String msg = message.getEditText().getText().toString(); // Initializing SmsManager variable SmsManager smsManager = SmsManager.getDefault(); //storing meesage in parts using Arraylist ArrayList<String> parts = smsManager.divideMessage(msg); ArrayList<PendingIntent> sentIntents = new ArrayList<>(); ArrayList<PendingIntent> deliveredIntents = new ArrayList<>(); for (int i = 0; i < parts.size(); i++) { sentIntents.add(null); deliveredIntents.add(null); } // Sending message to the caller smsManager.sendMultipartTextMessage(phoneNumber, null, parts, null, null); Log.d(TAG, "Auto-reply SMS sent to " + phoneNumber); } // Creating a method to handle Permission request result // If user allows the allows the permission it will start the service @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); // Checking if the user granted all the permission if (requestCode == REQUEST_CODE_PERMISSIONS) { boolean allGranted = true; for (int grantResult : grantResults) { if (grantResult != PackageManager.PERMISSION_GRANTED) { allGranted = false; break; } } // If all permissions are granted start the service if (allGranted) { startAutoReplyService(); } else { Toast.makeText(this, "Please grant the necessary permissions first", Toast.LENGTH_SHORT).show(); } } } // Overriding onDestroy method to unregister the callReceiver when the activity is destroyed. @Override protected void onDestroy() { super.onDestroy(); unregisterReceiver(callReceiver); } }
Now we need to add the following code to the app level manifest file so that android OS knows what permissions this app requires.
<uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.SEND_SMS" /> <uses-permission android:name="android.permission.READ_CALL_LOG" />
Android Call Managing App Output
Summary:
In this project, we learned how to build an Android Call managing app using Java that sends an SMS to the caller when a user doesn’t pick up calls i.e., missed calls. We started by creating a new Android Studio project and adding the necessary permissions for the app.
Then, we added a BroadcastReceiver to handle incoming calls and detect missed calls. After that, we created an SMS manager class that sends an SMS to the caller’s phone number. Finally, we tested the app and made some improvements to the user interface.
This project is just a starting point, and you can build on this app by adding more features like call logs, contact integration, and more. With the skills you learned in this tutorial, you can create more complex Android apps that help you stay connected with your contacts.