安卓系统在呼出电话时检测线路是否已被接通[英] Android detecting when lines have been connected during an outgoing call

本文是小编为大家收集整理的关于安卓系统在呼出电话时检测线路是否已被接通的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

只是一个快速背景,我在rooted nexus上运行cm7. 我正在尝试检测何时呼出呼叫实际连接:已停止响铃,并且您所在的人已被回答.透过论坛看,这似乎是一个艰难的问题,也许是未答复的问题.我真的很感激深入了解这一点.

在我的搜索中,我能找到的最好的就是: Android:如何获得说明拨出电话已得到解答? @pattabiraman说:"而不是检测到呼叫连接状态,它很容易获得最后拨打的呼叫的持续时间." 他是否意味着随着呼叫正在进行中,人们应该得到最后拨打的呼叫的持续时间?当这个持续时间超过0然后你知道吗?

推荐答案

类com.android.internal.telephony.CallManager应该有关于呼叫实际回答时的信息.它具有返回CallManager实例的公共静态方法getInstance(),以及一个公共方法getActiveFgCallState(),它将当前呼叫状态返回为Call.State枚举.
所以在理论上这样的东西可能有效:

Method getFgState = null;
Object cm = null;

try {
  Class cmDesc = Class.forName("com.android.internal.telephony.CallManager");
  Method getCM = cmDesc.getMethod("getInstance");
  getFgState = cmDesc.getMethod("getActiveFgCallState");
  cm = getCM.invoke(null);
} catch (Exception e) {
  e.printStackTrace();
}

然后反复轮询状态:

Object state = getFgState.invoke(cm);
if (state.toString().equals("IDLE")) {
  ...
} else if (state.toString().equals("ACTIVE")) {
  // If the previous state wasn't "ACTIVE" then the
  // call has been established.
}

我没有验证这实际上是有效的.即使它你必须要记住,API可能会改变,因为这不是应用程序开发人员应该依赖的东西.

其他推荐答案

我已经研究了代码. 除非您实例化手机对象并将其设置为默认电话,否则它将始终给出NULL. 但实例化它需要一些系统权限允许到系统APS.

通过使用此方法: com.android.internal.telephony.phonefactory#公共静态void makedefaultphones(上下文上下文){

http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.0.4_r1.2/com/android/internal/电话/phonefactory.java

本文地址:https://www.itbaoku.cn/post/102621.html

问题描述

Just a quick background I'm Running CM7 on a rooted Nexus one. I am trying to detect when an outgoing call is actually connected: has stopped ringing and the person you are calling has answered. Looking through the forums this seems to be a tough and perhaps unanswered question. I'd really appreciate any insight into this.

In my searching the best I could find was in: Android : How to get a state that the outgoing call has been answered? @PattabiRaman said: "instead of detecting the outgoing call connection state, it is easy to get the duration of the last dialed call." Does he mean that one should get the duration of the last dialed call as the call is in progress? And when that duration goes over 0 then you know?

推荐答案

The class com.android.internal.telephony.CallManager should have information about when the call actually is answered. It has a public static method getInstance() which returns the CallManager instance, and a public method getActiveFgCallState() which returns the current call state as a Call.State enum.
So in theory something like this might work:

Method getFgState = null;
Object cm = null;

try {
  Class cmDesc = Class.forName("com.android.internal.telephony.CallManager");
  Method getCM = cmDesc.getMethod("getInstance");
  getFgState = cmDesc.getMethod("getActiveFgCallState");
  cm = getCM.invoke(null);
} catch (Exception e) {
  e.printStackTrace();
}

And then repeatedly poll the state:

Object state = getFgState.invoke(cm);
if (state.toString().equals("IDLE")) {
  ...
} else if (state.toString().equals("ACTIVE")) {
  // If the previous state wasn't "ACTIVE" then the
  // call has been established.
}

I haven't verified that this actually works. And even if it does you'll have to keep in mind that the API could change, since this isn't something that app developers are supposed to rely on.

其他推荐答案

I have looked into the code. It will always give null unless you instantiate a Phone object and set it as default Phone. But instantiating it needs some System permissions allowed only to system aps.

By using this method: com.android.internal.telephony.PhoneFactory# public static void makeDefaultPhones(Context context) {

http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.0.4_r1.2/com/android/internal/telephony/PhoneFactory.java