Incoming call broadcast receiver

后端 未结 1 959
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-11 06:24

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

相关标签:
1条回答
  • 2021-02-11 07:09

    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
        }
    }
    
    0 讨论(0)
提交回复
热议问题