Android判断当前正在通话(非空闲)的状态

   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; 

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值