How to import com.android.internal.telephony.ITelephony to the Android application

前端 未结 2 1993
一生所求
一生所求 2020-12-01 13:33

I want to hang up incoming call I detect it and then I want to hang it up.

The problem is that this: com.android.internal.telephony.ITelephony is not re

相关标签:
2条回答
  • 2020-12-01 13:47

    The ITelephony interface is internal, so you cannot get a standard reference to it. You could use reflection all the way, i.e.

    TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
    
    Method m1 = tm.getClass().getDeclaredMethod("getITelephony");
    m1.setAccessible(true);
    Object iTelephony = m1.invoke(tm);
    
    Method m2 = iTelephony.getClass().getDeclaredMethod("silenceRinger"); 
    Method m3 = iTelephony.getClass().getDeclaredMethod("endCall"); 
    
    m2.invoke(iTelephony);
    m3.invoke(iTelephony);
    

    But either way those methods need the MODIFY_PHONE_STATE permission, which can only be granted to system apps. So I'm afraid it won't work anyway.

    0 讨论(0)
  • 2020-12-01 13:50

    For kotlin:

     val tm = context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
     val m1 = tm::class.java.getDeclaredMethod("getITelephony")
     m1.setAccessible(true)
     val telephonyService = m1.invoke(tm)
     val m2 = telephonyService::class.java.getDeclaredMethod("silenceRinger")
     val m3 = telephonyService::class.java.getDeclaredMethod("endCall")
    
     m2.invoke(telephonyService)
     m3.invoke(telephonyService)
    
    0 讨论(0)
提交回复
热议问题