How To Create A Calling Application In Android Using Android Studio

Introduction

Android is one of the most popular operating systems for mobile. In this article, I will show you how to create a Calling Application in Android Using Android Studio.

Requirements

Steps to be followed

Follow these steps to create a Calling Application in Android Using Android Studio. I have included the source code in the attachment.

Step 1

Open Android Studio and start a new Android Studio Project.

Android

Step 2

You can choose your application name and choose where your project is stored on the location. If you wish to use C++ for coding the project, mark the "Include C++ support", and click "Next" button.

Android

Now, select the version of Android and select the target Android devices.

Android

Step 3

Now, add the activity and click "Next" button.

Android

Add activity name and click "Finish".

Android

Step 4

Go to activity_main.xml. This XML file contains the designing code for your Android app.

Android

The XML code is given below.

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     xmlns:app="http://schemas.android.com/apk/res-auto"  
  4.     xmlns:tools="http://schemas.android.com/tools"  
  5.     android:layout_width="match_parent"  
  6.     android:layout_height="match_parent"  
  7.   
  8.     tools:context="abu.call.MainActivity" >  
  9.  <RelativeLayout  
  10.         android:layout_width="match_parent"  
  11.         android:layout_height="wrap_content"  
  12.         android:orientation="vertical">  
  13.   
  14.   
  15.     <TextView  
  16.         android:id="@+id/textView1"  
  17.         android:layout_width="wrap_content"  
  18.         android:layout_height="wrap_content"  
  19.         android:text="Dial No." />  
  20.     <Button  
  21.         android:id="@+id/button1"  
  22.         android:layout_width="wrap_content"  
  23.         android:layout_height="wrap_content"  
  24.         android:layout_alignLeft="@+id/textView1"  
  25.         android:layout_below="@+id/textView1"  
  26.         android:layout_marginLeft="44dp"  
  27.         android:layout_marginTop="84dp"  
  28.         android:text="Call" />  
  29.     <EditText  
  30.         android:id="@+id/editText1"  
  31.         android:layout_width="wrap_content"  
  32.         android:layout_height="wrap_content"  
  33.         android:layout_alignLeft="@+id/textView1"  
  34.         android:layout_below="@+id/textView1"  
  35.         android:layout_marginLeft="18dp"  
  36.         android:ems="10" >  
  37.         <requestFocus />  
  38.     </EditText>  
  39. </RelativeLayout>  
  40. </android.support.constraint.ConstraintLayout>  

Step 5

Go to  Main Activity.java. This Java program is the backend language of the Android app.

Android

The Java code is given below

  1. package abu.call;  
  2.   
  3. import android.Manifest;  
  4. import android.content.pm.PackageManager;  
  5. import android.net.Uri;  
  6. import android.os.Bundle;  
  7. import android.app.Activity;  
  8. import android.content.Intent;  
  9. import android.support.v4.app.ActivityCompat;  
  10. import android.view.Menu;  
  11. import android.view.View;  
  12. import android.view.View.OnClickListener;  
  13. import android.widget.Button;  
  14. import android.widget.EditText;  
  15.   
  16. public class MainActivity extends Activity  
  17. {  
  18.     EditText et;  
  19.     Button call_btn;  
  20.     @Override  
  21.     protected void onCreate(Bundle savedInstanceState)  
  22.     {  
  23.         super.onCreate(savedInstanceState);  
  24.         setContentView(R.layout.activity_main);  
  25.         et=(EditText)findViewById(R.id.editText1);  
  26.         call_btn=(Button)findViewById(R.id.button1);  
  27.         call_btn.setOnClickListener(new OnClickListener()  
  28.         {  
  29.             @Override  
  30.             public void onClick(View v)  
  31.             {  
  32.                 // TODO Auto-generated method stub  
  33.                 Intent i = new Intent(Intent.ACTION_CALL);  
  34.                 i.setData(Uri.parse("tel:"+et.getText().toString()));  
  35.                 startActivity(i);  
  36.             }  
  37.         });  
  38.     }  
  39. }  

Step 6

We need to make call requests, so add call permissions in AndroidManifest.xml.

Android

The AndroidManifest.xml code is given below.

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     package="abu.call">  
  4.   
  5.     <uses-permission android:name="android.permission.CALL_PHONE" />  
  6.     <application  
  7.         android:allowBackup="true"  
  8.         android:icon="@mipmap/ic_launcher"  
  9.         android:label="@string/app_name"  
  10.         android:roundIcon="@mipmap/ic_launcher_round"  
  11.         android:supportsRtl="true"  
  12.         android:theme="@style/AppTheme">  
  13.         <activity android:name=".MainActivity">  
  14.             <intent-filter>  
  15.                 <action android:name="android.intent.action.MAIN" />  
  16.   
  17.                 <category android:name="android.intent.category.LAUNCHER" />  
  18.             </intent-filter>  
  19.         </activity>  
  20.     </application>  
  21.   
  22. </manifest>  

Step 7

Now, go to menu bar and click "Make Project" or press ctrl+f9 so as to debug it from errors.

Android

Step 8

Then, click "Run" button or press shift+f10 to run the project. Choose the "virtual machine" option and click OK.

Android

Conclusion

We have successfully created a Calling application in Android using Android Studio.

Android

Android

Up Next
    Ebook Download
    View all
    Learn
    View all