How to make a phone call from your application


SDK Version: 
M3

To enable your application to initiate a phone call, you must set permissions in the manifest file:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3.       package="com.bubudsadasdas"
  4.       android:versionCode="1"
  5.       android:versionName="1.0">
  6.     <application android:icon="@drawable/icon" android:label="@string/app_name">
  7.         <activity android:name=".phonecalls"
  8.                   android:label="@string/app_name">
  9.             <intent-filter>
  10.                 <action android:name="android.intent.action.MAIN" />
  11.                 <category android:name="android.intent.category.LAUNCHER" />
  12.             </intent-filter>
  13.         </activity>
  14.  
  15.     </application>
  16.     <uses-sdk android:minSdkVersion="3" />
  17. <uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
  18. </manifest>

Now create a new activity with a call method. It should look like this:

  1. private void call() {
  2.     try {
  3.         Intent callIntent = new Intent(Intent.ACTION_CALL);
  4.         callIntent.setData(Uri.parse("tel:123456789"));
  5.         startActivity(callIntent);
  6.     } catch (ActivityNotFoundException e) {
  7.         Log.e("helloandroid dialing example", "Call failed", e);
  8.     }
  9. }

What happens when you start a phone call depends, in part, on the telephone network. The number may be incorrect. The network may be busy or otherwise unavailable. The call can be interrupted. Here, however, you see no error-handling logic, except for catching and logging exceptions that can be thrown if Android's system encounters a problem when finding applications that can process Intent objects.

Now call the call :) method in an empty activity:

  1. import android.app.Activity;
  2. import android.content.ActivityNotFoundException;
  3. import android.content.Intent;
  4. import android.net.Uri;
  5. import android.os.Bundle;
  6. import android.util.Log;
  7.  
  8. public class phonecalls extends Activity {
  9.     /** Called when the activity is first created. */
  10.     @Override
  11.     public void onCreate(Bundle savedInstanceState) {
  12.         super.onCreate(savedInstanceState);
  13.         setContentView(R.layout.main);
  14.         call();
  15.     }
  16.  
  17. private void call() {
  18.     try {
  19.         Intent callIntent = new Intent(Intent.ACTION_CALL);
  20.         callIntent.setData(Uri.parse("tel:123456789"));
  21.         startActivity(callIntent);
  22.     } catch (ActivityNotFoundException activityException) {
  23.          Log.e("helloandroid dialing example", "Call failed", e);
  24.     }
  25. }
  26.  
  27. }



Feel free to download the complete source code from here.

Comments

Actually, ain't that computer techie so I don't really understand the commands. I'm so thankful that you gave a pretty much clearer discussion on how to make phone call from my application.Anthony Cole
micheal

Hey i think of your blog is pretty - i found it pleasant in google and I put on my list of favorites would like to see more posts from u soon.
Anotonio rogers

Can anyone help me in getting the code to cancel an incoming call. Couldnt find anything in TelephoneManager.

failing and admirable bailey button not acquaint this classic cardy exclusive, abundant adviser of new styles that address in fact additional you achieve chop chop for buck. shoe

These days with people always on the move yet wanting to carry their business with them internet on the move with your laptop is a necessity. With internet dongles you can connect to the internet anytime anywhere. Find the best deals on dongles

Many people have access to Internet and use a VoIP provider like Skype to make international calls, and in fact, if you have friends and family who have a computer with Internet access, there is no reason why we have to pay anything for VoIP calls - just to be on the same VoIP network. best led tv

I need to test it, I will let you know the minute I was able to place a call using this piece of code.
When I will finally figured it out and it was exactly as you described.
I will use it for sure in the future.
sytropin

Good info, I had never known how to make a call from an application. Next on my list is creating my own personal ringtone, although I know that will be a big less complicated.

Actually, ain't that computer techie so I don't really understand the commands. I'm so thankful that you gave a pretty much clearer discussion on how to make phone call from my application.Anthony Cole

You don't need to ask for the "CALL_PHONE" permission unless you need to bypass the dialer. When you use the intent without the permission, the dialer will show the number but won't call yet, and the user can then choose to call (or save) the number.

Please help stamp out permission creep and don't ask for unnecessary ones, it discourages users from installing your application. See http://developer.android.com/reference/android/content/Intent.html for more information.

Most of the code, I have learned easily. But still, some code is confusing me. I am sure that some code is missing in it.

Cell Phone Repair

Thanks for sharing this how to process. The step by step process is very easy to follow. Specifically, the numbering part make everything more clearer.Pete Frost