Reputation: 161
I've used the following code to disconnect a call programatically but It's not working.
private void callDisconnect(){
try{
TelephonyManager manager = (TelephonyManager)this.getSystemService(this.TELEPHONY_SERVICE);
Class c = Class.forName(manager.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
ITelephony telephony = (ITelephony)m.invoke(manager);
telephony.endcall();
} catch(Exception e){
Log.d("",e.getMessage());
}
}
Can anybody help me with this?? Do I need to change the code or something...??
Upvotes: 2
Views: 7289
Reputation: 65
You can block the outgoing call using the setResultData(null) function in the onReceive method of the Broadcast receiver.
public class BlockOutgoing 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);
setResultData(null);
Toast.makeText(context, "Outgoing Call Blocked" , 5000).show();
}
}
<receiver
android:name=".BlockOutgoing"
android:label="@string/app_name" >
<intent-filter android:priority="1">
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>
Upvotes: 1
Reputation: 51
Simply use this broadcastreceiver. I tested it in one of my application and it works perfectly.
public class MyBroadcastReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, final Intent intent)
{
if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL))
{
String phoneNumber = intent.getExtras().getString(Intent.EXTRA_PHONE_NUMBER);
if (phoneNumber.equals("123456"))
{
if (getResultData() != null)
{
setResultData(null);
}
}
}
}
}
Upvotes: 5
Reputation: 132992
For disconnecting a call programmatically you must add ITelephony.AIDL
file in your project. If you have added it, then your package name must be com/android/internal/telephony/ITelephony.AIDL
: for more information see Blocking Incoming call. Download the AIDL file from here.
To disconnect a call use endCall();
method of ITelephony
Upvotes: 5
Reputation: 14058
It is not possible anymore in newer versions of android. The user decides when to end the call if it has already started. You can however block calls from happening.
Upvotes: 1
Reputation: 8079
You cannot end a call like that in android 2.3+... using your code... I think only user can end his call...and for earlier versions You can see this link and This one
Upvotes: -1