简体   繁体   中英

Incoming call broadcast receiver

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM