本文介绍了如何访问com.android.internal.telephony.CallManager?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图访​​问 CallManager的类对象从 com.android.internal.telephony 包。

I am trying to access CallManager class object from com.android.internal.telephony package.

下面是我的code:

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的

Unfortunately, this is throwing a ClassNotFoundException. The same approach allows me to access PhoneFactory, but apparently I'm not allowed to access CallManager.

如果我能达到的类,那么我想使用类进行如下操作:

If I could reach the class, then I'd want to proceed using the class as follows:

Method method_getInstance;
method_getInstance = classCallManager.getDeclaredMethod("getInstance");
method_getInstance.setAccessible(true);
Object callManagerInstance = method_getInstance.invoke(null);

任何人都可以帮助我在这?

Can anyone help me on this?

在前进,
谢谢戒ç

Thanks in advance,
Harsha C

推荐答案

我能成功加载CallManager和它的方法。然而,当我调用的getState(),getActiveFgCallState(),它总是返回空闲即使当应用程序接收到来自TelephonyManager,即TelephonyManager.CALL_STATE_IDLE,TelephonyManager.CALL_STATE_OFFHOOK,TelephonyManager.CALL_STATE_RINGING不同的呼叫状态。

I could successfully load CallManager and its methods. However, when I invoke getState(), getActiveFgCallState(), it always return IDLE even when the app receives different call states from TelephonyManager, i.e. TelephonyManager.CALL_STATE_IDLE, TelephonyManager.CALL_STATE_OFFHOOK, TelephonyManager.CALL_STATE_RINGING.

我用下面的code加载类及其方法:

I used the following code to load the class and its methods:

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));

顺便说一句,我所要做的是检测的时候,手机响起。我在源$ C ​​$ c表示ALERTING是内部事件,我应该听看到的。因此,我试图用CallManager的获得Call.State,而不是Phone.State。我还试图用registerFor preciseCallStateChanges CallManager的类的(),但没有上前工作至今。

Btw, what I am trying to do is detecting when the phone starts ringing. I saw in the source code that ALERTING is the internal event that I should listen to. Therefore, I tried to use CallManager to get Call.State, rather than Phone.State. I also tried to use registerForPreciseCallStateChanges() of CallManager class but none of approached worked so far.

这篇关于如何访问com.android.internal.telephony.CallManager?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 02:15