0

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.

Armin
  • 599
  • 2
  • 8
  • 19
  • I tried it before, its not possible to do so. – Psypher Jan 24 '15 at 19:42
  • Try the PhoneStateListener that is used here to dynamically change the ringtone for a call: http://stackoverflow.com/questions/3387556/incoming-call-dynamically-override-default-ringtone – Price Jan 24 '15 at 19:52
  • @Price Would you explain more ? – Armin Jan 24 '15 at 20:05
  • See if the method `PhoneStateListener.onCallStateChanged()` that is used in that example is called before the first ring. Since it was used to dynamically change the ringtone, I'm guessing that it may have been called before the phone started ringing. – Price Jan 24 '15 at 20:22

0 Answers0