在Android中获取不同的通话状态

发布于 2024-11-26 15:11:16 字数 530 浏览 2 评论 0原文

我正在尝试使用 Java 反射来访问 CallManager 并检测呼叫状态,我总是让呼叫空闲。请帮我解决这个问题。 顺便说一句,我使用以下代码来访问 CallManager:

try{ 
    class classCallManager = class.forname("com.android.internal.telephony.CallManager");
    Method methodGetInstance = classCallManager .getDeclaredMethod("getInstance");
    methodGetInstance.setAccessible(true);
    Object objectCallManager = methodGetInstance.invoke(null);
    Method methodGetActiveFgCallState = classCallManager.getDeclaredMethod("getActiveFgCallState");
}catch (Exception e) {}

I am trying to use Java reflection to access CallManager and detect the call state which I always get the call idle. Please help me on this.
Btw I use the following code to access CallManager:

try{ 
    class classCallManager = class.forname("com.android.internal.telephony.CallManager");
    Method methodGetInstance = classCallManager .getDeclaredMethod("getInstance");
    methodGetInstance.setAccessible(true);
    Object objectCallManager = methodGetInstance.invoke(null);
    Method methodGetActiveFgCallState = classCallManager.getDeclaredMethod("getActiveFgCallState");
}catch (Exception e) {}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

话少心凉 2024-12-03 15:11:16

我可以确认,不幸的是,即使尝试获取活动的 fg 调用也会失败:返回值始终为 false

    val classCallManagerName = "com.android.internal.telephony.CallManager"

    log log "get class name manager"

    val classCallManager = Class.forName(classCallManagerName)

    future {
      var msec = 15000

      val sleeptime = 500

      while (
        msec > 0
      ) {
        log log "get method instance"

        //getDeclaredMethod
        val methodGetInstance = classCallManager.getMethod("getInstance")

        log log "set method get instance accessible"

        methodGetInstance.setAccessible(true)

        log log "invoke get instance"

        val objectCallManager = methodGetInstance.invoke(null) //null for static methods

        log log "getMethod hasActiveFgCall"

        //getActiveFgCallState
        val hasActiveFgCall = classCallManager.getMethod("hasActiveFgCall")

        log log "hasActiveFgCall setAccessible(true)"

        hasActiveFgCall.setAccessible(true)

        log log "has active fg call: " + hasActiveFgCall.invoke(objectCallManager)

        Thread.sleep(sleeptime)

        msec -= sleeptime
      }
    }

请注意,代码位于 Scala 中

I can confirm that unfortunately even trying to get active fg call fails: the return value is always false

    val classCallManagerName = "com.android.internal.telephony.CallManager"

    log log "get class name manager"

    val classCallManager = Class.forName(classCallManagerName)

    future {
      var msec = 15000

      val sleeptime = 500

      while (
        msec > 0
      ) {
        log log "get method instance"

        //getDeclaredMethod
        val methodGetInstance = classCallManager.getMethod("getInstance")

        log log "set method get instance accessible"

        methodGetInstance.setAccessible(true)

        log log "invoke get instance"

        val objectCallManager = methodGetInstance.invoke(null) //null for static methods

        log log "getMethod hasActiveFgCall"

        //getActiveFgCallState
        val hasActiveFgCall = classCallManager.getMethod("hasActiveFgCall")

        log log "hasActiveFgCall setAccessible(true)"

        hasActiveFgCall.setAccessible(true)

        log log "has active fg call: " + hasActiveFgCall.invoke(objectCallManager)

        Thread.sleep(sleeptime)

        msec -= sleeptime
      }
    }

note that the code is in Scala

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文