我正在尝试从com.android.internal.telephony包访问CallManager类对象。
下面是我的代码:
ClassLoader classLoader = TestActivity.class.getClassLoader();
final ClassLoader classLoader = this.getClass().getClassLoader();
try {
final Class<?> classCallManager =
classLoader.loadClass("com.android.internal.telephony.CallManager");
Log.i("TestActivity", classCallManager);
} catch (final ClassNotFoundException e) {
Log.e("TestActivity", e);
}不幸的是,这是抛出一个ClassNotFoundException。同样的方法允许我访问PhoneFactory,但显然不允许我访问CallManager。
如果我可以访问这个类,那么我想继续使用这个类,如下所示:
Method method_getInstance;
method_getInstance = classCallManager.getDeclaredMethod("getInstance");
method_getInstance.setAccessible(true);
Object callManagerInstance = method_getInstance.invoke(null);有人能在这方面帮我吗?
提前谢谢你,
哈莎·C
发布于 2011-03-31 14:01:00
我可以成功地加载CallManager及其方法。然而,当我调用getState(),getActiveFgCallState()时,它总是返回IDLE,即使应用程序从TelephonyManager接收到不同的调用状态,即TelephonyManager.CALL_STATE_IDLE,TelephonyManager.CALL_STATE_OFFHOOK,TelephonyManager.CALL_STATE_RINGING。
我使用以下代码加载类及其方法:
final Class<?> classCallManager = classLoader.loadClass("com.android.internal.telephony.CallManager");
Log.i(TAG, "Class loaded " + classCallManager.toString());
Method methodGetInstance = classCallManager.getDeclaredMethod("getInstance");
Log.i(TAG, "Method loaded " + methodGetInstance.getName());
Object objectCallManager = methodGetInstance.invoke(null);
Log.i(TAG, "Object loaded " + objectCallManager.getClass().getName());
Method methodGetState = classCallManager.getDeclaredMethod("getState");
Log.i(TAG, "Method loaded " + methodGetState.getName());
Log.i(TAG, "Phone state = " + methodGetState.invoke(objectCallManager));顺便说一句,我想要做的是检测电话何时开始响铃。我在源代码中看到,警报是我应该监听的内部事件。因此,我尝试使用CallManager来获取Call.State,而不是Phone.State。我也尝试过使用CallManager类的registerForPreciseCallStateChanges()方法,但是到目前为止都没有成功。
发布于 2012-07-19 15:00:09
我必须解决完全相同的问题--在电话挂断时找出断开的原因。我的解决方案是grep相关线路的无线电日志。似乎起作用了-希望它能帮上忙。
private void startRadioLogListener() {
new Thread(new Runnable() {
public void run() {
Process process = null;
try {
// Clear the log first
String myCommandClear = "logcat -b radio -c";
Runtime.getRuntime().exec(myCommandClear);
String myCommand = "logcat -b radio";
process = Runtime.getRuntime().exec(myCommand);
Log.e(LogHelper.CAL_MON, "RadioLogProc: " + process);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
while (true) {
final String line = bufferedReader.readLine();
if (line != null) {
if (line.contains("disconnectCauseFromCode") || line.contains("LAST_CALL_FAIL_CAUSE")) {
Log.d(LogHelper.CAL_MON, "RadioLog: " + line);
radioLogHandler.post(new Runnable() {
public void run() {
consolePrint("Radio: " + line + "\n");
}
});
}
}
}
} catch (IOException e) {
Log.e(LogHelper.CAL_MON, "Can't get radio log", e);
} finally {
if (process != null) {
process.destroy();
}
}
}
}).start();
}发布于 2011-02-16 00:58:55
您尝试过在此blog上找到的此方法吗
通过加载Phone.apk可能是绕过ClassNotFound异常错误的线索...
https://stackoverflow.com/questions/4745899
复制相似问题