我使用以下代码来处理来自服务内的传入呼叫。当我调用 endCall 方法时(我手机的 Android 版本是 ICS),它工作得很好。但是,当我调用 answerRingingCall 方法时,我收到一个异常,因为没有修改电话状态的权限。我知道 Google 在某一时刻撤销了这一权限,但由于我可以调用结束调用方法,因此无法调用应答调用方法的解释是什么?我的意思是..这两种方法都会修改手机的状态,那么怎么回事?有没有办法来解决这个问题?
try {
TelephonyManager tm = (TelephonyManager)getBaseContext().getSystemService(Context.TELEPHONY_SERVICE);
Class c = Class.forName(tm.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
Object telephonyService = m.invoke(tm); // Get the internal ITelephony object
c = Class.forName(telephonyService.getClass().getName()); // Get its class
m = c.getDeclaredMethod("endCall"); // Get the "endCall()" method
m.setAccessible(true); // Make it accessible
m.invoke(telephonyService); // invoke endCall()
}
catch (Exception e) {
Log.w("exception",e);
}
如果我不得不猜测,我会说在 Phone.apk 内的 com.android.phone.PhoneInterfaceManager 的 OEM 版本中,endCall 函数不会调用 enforceCallPermission();在发送结束通话的请求之前。
在answerRingingCall函数中调用enforceCallPermission();
您可以尝试进行黑客攻击,在 ITelephony 对象上访问私有方法,将 sendRequestAsync 设置为 true,然后使用 4 作为输入参数(又名 CMD_ANSWER_RINGING_CALL)调用它。
这将避免权限检查。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)