Thursday 18 October 2012

Intercept Outgoing Call


This tutorial is to Intercept the Outgoing Call that is made from the Android Phone.

Step 1: Create a broadcast Receiver

First you need to create a Broadcast Receiver, Create OutgoingCallActivity.java file

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;
public class OutgoingCallActivity extends BroadcastReceiver
{
String number;
@Override
public void onReceive(Context context, Intent intent)
{
Log.d("12280", "asdasNumber is-->> " + number);
number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
Toast.makeText(context, "Call made to-->>" + number, 5000).show();
}
}
Here EXTRA_PHONE_NUMBER is used to get the number on which call is made, which would be displayed using the Toast.
If you want to divert the call to a specified number instead of the number that is dialed, just add the following line in the onReceive method,
setResultData("111");
The call would be made to the 111 number.
Also if you want to end the call, add this line
setResultData(null); 

Step 2: Changes in the manifest file

   <uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <receiver
            android:name=".OutgoingCallActivity"
            android:label="@string/app_name" >
            <intent-filter android:priority="1">
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
            </intent-filter>
        </receiver>
    </application>
Here Permission is required to Intercept and Process the Outgoing Call.

Regards:
sahil Mahajan Mj

1 comment:

  1. Hi,this is not working for me?
    Can you please give me your source code?

    ReplyDelete