Step 1: Create a broadcast Receiver
First you need to create a Broadcast Receiver, Create OutgoingCallActivity.java file
import android.content.BroadcastReceiver;Here EXTRA_PHONE_NUMBER is used to get the number on which call is made, which would be displayed using the Toast.
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();
}
}
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" />Here Permission is required to Intercept and Process the Outgoing Call.
<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>
Regards:
sahil Mahajan Mj
Hi,this is not working for me?
ReplyDeleteCan you please give me your source code?