No such method getITelephony to disconnect Call
Asked Answered
P

3

11

i want to disconnect outgoing call in ICS.

My issue is first of all I am not getting the broadcast in IC` in Gingerbread it is working fine and blocking the calls but in ICS its not Broadcasting.

for BroadCast I created a service and in that I am getting BroadCast of PHONE_STATE in ICS also but when i try to disconnect call I am getting error of

NO such method name 'getITelephony'

in ICS call is not disconnecting.

I am using following code to disconnect call using the BroadCast...

try{
       TelephonyManager manager = (TelephonyManager)context.getSystemService(Context.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());
  }

AndroidMaifest.xml

PhonecallStateBroadcastReceiver.java

with packgename of package com.android.internal.telephony;

ITelephony.aidl

interface ITelephony 
{
    boolean endCall();
    void answerRingingCall();
    void silenceRinger();
}
Pulmonary answered 11/4, 2013 at 10:3 Comment(1)
i am getting same problem in google nexusNecessary
P
2

1) Download this class : ITelephony

2) Add this class.java in your project in package: com.android.internal.telephony

3) Add this permission in your manifest :

<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />

And this receiver in application balise :

<receiver android:name=".CallReceiver" >
   <intent-filter>
     <action android:name="android.intent.action.PHONE_STATE" />
   </intent-filter>
</receiver>

4) Create CallReceiver class :

@Override
public void onReceive(Context context, Intent intent) {
    ITelephony telephonyService = getTeleService(context);
    if(telephonyService!=null) {
        try {
            String numberCall = intent.getExtras().getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
            Log.i("TAG", "CALL NUM: " + numberCall);
            if(numberCall.equals(TEST_NUMBER)) {
                telephonyService.endCall();
                Toast.makeText(context, "END CALL: " + numberCall, Toast.LENGTH_LONG).show();
                Log.i("TAG", "END CALL");
            } else {
                Log.i("TAG", "ACCEPT CALL");
            }
        } catch (Exception e) {
            e.printStackTrace();
            Log.i("TAG", "CATCH CALL");
        }
    }
}

private ITelephony getTeleService(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    try {
        Method m = Class.forName(tm.getClass().getName()).getDeclaredMethod("getITelephony");
        m.setAccessible(true);
        return (ITelephony) m.invoke(tm);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Plectognath answered 17/5, 2013 at 19:25 Comment(2)
You can also download ITelephony.aidl here -> github.com/android/platform_frameworks_base/blob/master/…Plectognath
Is there a way to direct call to voice mail?Reservoir
T
1

use of reflection to get access to "getITelephony" won't work in Android 2.3+

Reference:

http://hive-mind.org/android-call-blocking

How do you programmatically end a call on 2.3+?

Tade answered 11/4, 2013 at 10:19 Comment(4)
i know that it is not working that's why i had posted this question and the other link I already checked its also giving me same response...Pulmonary
then ur question should be modified appropriately to request the alternative solutionTade
but in that answer it is mentioned that silenceRinger() is not working but endCall() is just finePulmonary
yup. Just I have provided the reference for what I said not for an alternative solution.Tade
M
0

Class c = Class.forName("android.telephony.TelephonyManager"); this will solve your problem for Android 2.3+

Maratha answered 13/1, 2014 at 9:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.