Make a phone call directly from android app programmatically

How to create a android app and automatically call a mobile phone number on button click event.

In this tutorial we are creating android application with calling functionality so when app user click on button then it will automatically calls on defined mobile phone number. So here is the complete step by step tutorial for Make a phone call directly from android app programmatically.

android-project-download-code-button

Note : Please add CALL_PHONE permission inside your AndroidManifest.xml file.

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

How to Make a phone call directly from android app programmatically.

Code for MainActivity.java file.

package com.phonecalldirectly_android_examples.com;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends Activity {

 Button call;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 
 call = (Button)findViewById(R.id.button1);
 
 call.setOnClickListener(new View.OnClickListener() {
 
 @Override
 public void onClick(View v) {
 // TODO Auto-generated method stub
 
 
 Intent intent = new Intent(android.content.Intent.ACTION_CALL, Uri.parse("tel: +911234567890"));
 startActivity(intent);
 
 
 }
 });
 }
}

Code for activity_main.xml layout file.

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.phonecalldirectly_android_examples.com.MainActivity" >

 <Button
 android:id="@+id/button1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_centerHorizontal="true"
 android:layout_centerVertical="true"
 android:text="Click Here To Make a phone call directly from android app programmatically" />

</RelativeLayout>

Code for AndroidManifest.xml file.

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

 <uses-sdk
 android:minSdkVersion="8"
 android:targetSdkVersion="21" />

 <uses-permission android:name="android.permission.CALL_PHONE" />
 
 <application
 android:allowBackup="true"
 android:icon="@drawable/ic_launcher"
 android:label="@string/app_name"
 android:theme="@style/AppTheme" >
 <activity
 android:name=".MainActivity"
 android:label="@string/app_name" >
 <intent-filter>
 <action android:name="android.intent.action.MAIN" />

 <category android:name="android.intent.category.LAUNCHER" />
 </intent-filter>
 </activity>
 </application>

</manifest>

Screenshots:

Make a phone call directly from android app programmatically

Click here to download Make a phone call directly from android app programmatically project with source code.

Leave a Reply

Your email address will not be published. Required fields are marked *