Android-为什么endCall方法有效,但answerRingingCall不起作用? [英] Android - Why does endCall method work but answerRingingCall doesn't work?
问题描述
我使用以下代码来处理来自服务内的来电。当我调用endCall方法(我的手机的Android版本为ICS)时,它可以完美工作。但是,当我调用answerRingingCall方法时,由于没有权限修改电话状态而出现异常。我知道Google曾一度撤消了此权限,但是由于我可以调用结束调用方法,因此也无法调用应答调用方法的解释是什么?我的意思是..两种方法都会修改手机的状态,所以怎么了?有没有办法解决这个问题?
I use the following code to handle incoming calls from within a service. It works perfectly when i invode the endCall method (My phone's Android Version is ICS). But when I invoke the answerRingingCall method i get an exception for not having permission to modify phone state. I know that Google revoked this permission at one point but since i can invoke the end call method what is the explanation for not being able to invoke the answer call method as well? I mean..both methods modify the phone's state, so what's up? Is there a way to fix this?
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函数不会调用forceCallCallPermission();在发送结束呼叫的请求之前。
If I had to guess, I'd say in your OEM version of com.android.phone.PhoneInterfaceManager inside the Phone.apk the endCall function doesn't call enforceCallPermission(); before sending the request to end the call.
与在answerRingingCall函数中一样,调用executeCallPermission();
Where as in the answerRingingCall function calls enforceCallPermission();
您可以尝试破解,在ITelephony对象上访问private方法,将sendRequestAsync设置为true,然后将其作为输入参数4调用,即CMD_ANSWER_RINGING_CALL。
You could try a hack where you get access the the private method, on the ITelephony object, sendRequestAsync set accessible to true, and then call it with 4 as the input param, aka CMD_ANSWER_RINGING_CALL.
这将避免权限检查。
这篇关于Android-为什么endCall方法有效,但answerRingingCall不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!