android监听振铃,android – 如何确定“第2行”是否有呼叫振铃(例如呼叫等待)

我找到了一种方法来实现这个…发布它为“下一个人”.

简而言之,手机状态在三种状态之间移动:

>’空闲’ – 您没有使用手机

>’铃声’ – 来电正在进行中

>’OFF_HOOK’ – 电话没电了

当广播“RINGING”状态时,紧接着是IDLE或OFF_HOOK,以将状态恢复为预呼入状态.

把它们放在一起,你最终得到这个:

package com.telephony;

import android.content.BroadcastReceiver;

import android.content.Context;

import android.content.Intent;

import android.telephony.TelephonyManager;

public class PhoneStateChangedReciever extends BroadcastReceiver {

private static String lastKnownPhoneState = null;

@Override

public void onReceive(Context context, Intent intent) {

if(intent != null && intent.getAction().equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) {

//State has changed

String newPhoneState = intent.hasExtra(TelephonyManager.EXTRA_STATE) ? intent.getStringExtra(TelephonyManager.EXTRA_STATE) : null;

//See if the new state is 'ringing'

if(newPhoneState != null && newPhoneState.equals(TelephonyManager.EXTRA_STATE_RINGING)) {

//If the last known state was 'OFF_HOOK', the phone was in use and 'Line 2' is ringing

if(lastKnownPhoneState != null && lastKnownPhoneState.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {

...

}

//If it was anything else, the phone is free and 'Line 1' is ringing

else {

...

}

}

lastKnownPhoneState = newPhoneState;

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值