public boolean isTelephonyCalling() {
boolean calling = false;
//这样写是为了说明问题(可以直接不等于空闲就是通话中),下面两个值表示的三种情况:
// 1、可以想象为座机拿起话筒的状态:拿起话筒、通话<这个通话是没有其他来电或等待>。手机是没有话筒的,其实可以简单的理解为:有且只有一个通话正在进行(CALL_STATE_OFFHOOK)
// 2、有电话呼入(CALL_STATE_RINGING)
// 3、有电话接听时,又来了一个新电话,接听后另外一个电话处于等待状态(CALL_STATE_RINGING)
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
if (TelephonyManager.CALL_STATE_OFFHOOK == telephonyManager.getCallState() || TelephonyManager.CALL_STATE_RINGING == telephonyManager.getCallState()) {
calling = true;
}
return calling;
}
TelephonyManager 中的定义 :
/** Device call state: No activity. */
//空闲状态
public static final int CALL_STATE_IDLE = 0;
/** Device call state: Ringing. A new call arrived and is
* ringing or waiting. In the latter case, another call is
* already active. */
//振铃状态:1、一个新电话来了,2、或者用户接听了俩电话,一个电话处于等待。
public static final int CALL_STATE_RINGING = 1;
/** Device call state: Off-hook. At least one call exists
* that is dialing, active, or on hold, and no calls are ringing
* or waiting. */
//设备呼叫状态:摘机。至少存在一个呼叫,即拨号、激活或保留,并且没有来电或者等待。
public static final int CALL_STATE_OFFHOOK = 2;