我打算编写与 Phone 和 Direct SIM write 相关的测试。
如果所需的 API 未在 TelephonyManager 中公开,但作为私有(private) API 存在于 PhoneBase.java
、PhoneFactory.java
或 CommandInterface 中,有哪些替代方案.java
?
具体来说,我的问题是:
PhoneFactory.getDefaultPhone()
的“替代”是什么?- 访问
CommandsInterface
的替代方法是什么(例如:CommandsInterface mCmdIf = ((PhoneBase)mPhone).mCM
)?
提前致谢,
米迦
最佳答案
您可以使用java 反射
。
下面是我如何访问 com.android.internal.telephony.ITelephony
类的方法来阻止来电 ...
private void endCall() throws Exception {
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
Class<?> c = Class.forName(tm.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
ITelephony telephonyService = (ITelephony) m.invoke(tm);
telephonyService.silenceRinger();
telephonyService.endCall();
Toast.makeText(context, "Call Ended !", Toast.LENGTH_SHORT).show();
}
关于android - 如何访问未在 TelephonyManager 中公开的 Android 私有(private) API?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2778740/