Incoming call broadcast receiver

一笑奈何 提交于 2019-12-04 15:49:49

问题


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.


回答1:


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
    }
}


来源:https://stackoverflow.com/questions/8224049/incoming-call-broadcast-receiver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!