来电广播接收器接收器

2023-09-05 05:05:10 作者:花猫。

我已经注册incomingCall广播接收器,它工作正常,但我需要的时候接收呼叫建立(或拒绝)。我其实需要的是通知我,当用户preSS回答或拒绝的呼叫。

I have registered incomingCall broadcast receiver, and it works fine, but I need receiver when the call is established (or rejected). What I actually need is something to notify me when the user press 'Answer' or 'Reject' call.

推荐答案

您可以覆盖你的onReceive的BroadcastReceiver方法如下

You can override your onReceive method of BroadcastReceiver as below

public void onReceive(Context context, Intent intent) {

    String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);

    if(state.equals(TelephonyManager.EXTRA_STATE_RINGING)){
        //Phone is ringing

    }else if(state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK){
        //Call received


    }else if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)){
        //Call Dropped or rejected

    }

}