我正在开发Android 2.2 / 2.3,需要使用iTelephony提供的一些api。
我尝试过几种方法来访问一些隐藏的API,但它不起作用。
如果有人成功尝试或欢迎任何建议,请告诉我。
遇到异常:WARN / System.err(827):java.lang.NoSuchMethodException:getActiveCallsCount
EG。 getActiveCallsCount(); getHoldCallsCount(); getCallTime() etc...
以下是我的示例代码:
private void getActiveCallCounts() {
try {
Class serviceManagerClass = Class.forName("android.os.ServiceManager");
Method getServiceMethod = serviceManagerClass.getMethod("getService", String.class);
Object phoneService = getServiceMethod.invoke(null, "phone");
Class ITelephonyClass = Class.forName("com.android.internal.telephony.ITelephony");
Class ITelephonyStubClass = null;
for (Class clazz : ITelephonyClass.getDeclaredClasses()) {
if (clazz.getSimpleName().equals("Stub")) {
ITelephonyStubClass = clazz;
break;
}
}
if (ITelephonyStubClass != null) {
Class IBinderClass = Class.forName("android.os.IBinder");
Method asInterfaceMethod = ITelephonyStubClass.getDeclaredMethod("asInterface", IBinderClass);
Object iTelephony = asInterfaceMethod.invoke(null, phoneService);
if (iTelephony != null) {
Method getActiveCallsCountMethod = iTelephony.getClass().getMethod("getActiveCallsCount");
Integer output= getActiveCallsCountMethod.invoke(iTelephony);
System.out.println("got call count.. " + output.intValue());
} else {
Log.w("TTT", "Telephony service is null, can't call "
+ "getActiveCallsCount");
}
} else {
Log.d("TTT", "Unable to locate ITelephony.Stub class!");
}
} catch (Exception ex) {
ex.printStackTrace();
Log.e("TTT", "Failed to get active call count due to Exception!" + ex.getMessage());
}
}
答案 0 :(得分:0)
您可以构建Android源代码,将输出out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes.jar
添加到项目的类路径中。然后你可以直接使用隐藏方法和内部类。
答案 1 :(得分:0)
这些方法(getActiveCallsCount(); getHoldCallsCount(); getCallTime())不包含在类com.android.internal.telephony.ITelephony
中