I'm trying to reject incoming calls without even getting a single ring to the calling person. I am trying to reject the calls by this code but it rejects with one ring.
public boolean killCall(Context context) {
try {
// Get the boring old TelephonyManager
TelephonyManager telephonyManager =
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
// Get the getITelephony() method
Class classTelephony = Class.forName(telephonyManager.getClass().getName());
Method methodGetITelephony = classTelephony.getDeclaredMethod("getITelephony");
// Ignore that the method is supposed to be private
methodGetITelephony.setAccessible(true);
// Invoke getITelephony() to get the ITelephony interface
Object telephonyInterface = methodGetITelephony.invoke(telephonyManager);
// Get the endCall method from ITelephony
Class telephonyInterfaceClass =
Class.forName(telephonyInterface.getClass().getName());
Method methodEndCall = telephonyInterfaceClass.getDeclaredMethod("endCall");
methodEndCall.setAccessible(true);
// Invoke endCall()
methodEndCall.invoke(telephonyInterface);
} catch (Exception ex) { // Many things can go wrong with reflection calls
return false;
}
return true;
}
i call killCall(Context context)
in public void onReceive(Context context, Intent intent)
of a BroadcastReceiver. i set CALL_PHONE
and READ_PHONE_STATE
permission for my app and here is the code for <receiver/>
in Manifest.xml
<receiver
android:name=".PhoneCallReciever"
android:enabled="true"
android:exported="true"
>
<intent-filter android:priority="999">
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
Please help me.