开发者

android: iTelephony

I am working on Android 2.2/2.3 and need to use some of the api's provided by iTelephony.

I have tried few ways to access some of the hidden APIs but it doesn't work.

Please let me know if anyone has attempt successfully or any suggestions are welcome.

Exception encountered: WARN/System.err(827): java.lang.NoSuchMethodException: getActiveCallsCount

Eg. getActiveCallsCount(); getHoldCallsCount(); getCallTime() etc...

Here is my sample code :

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()); 
                } els开发者_JS百科e {
                    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());
        } 

    }


You can build Android source code, add the output out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes.jar to your project's classpath. Then you can use the hidden method and internal class directly.


These methods (getActiveCallsCount(); getHoldCallsCount(); getCallTime()) not include in class com.android.internal.telephony.ITelephony

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜