来电广播接收器

时间:2011-11-22 08:43:53

标签: android broadcastreceiver

我已经注册了incomingCall广播接收器,它工作正常,但是当呼叫建立(或拒绝)时我需要接收器。当用户按“接听”或“拒绝”电话时,我实际需要的是通知我。

1 个答案:

答案 0 :(得分:9)

您可以覆盖BroadcastReceiver的onReceive方法,如下所示

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