0

如何在设备开始通话和结束通话时获得我的注册广播接收器的意图?不管是呼入电话还是呼出电话。我只需要在每次设备开始呼叫和结束呼叫时获取 Intent。

4

1 回答 1

1
private class PhoneCallListener extends PhoneStateListener {


    @Override
    public void onCallStateChanged(int state, String incomingNumber) {

        if (TelephonyManager.CALL_STATE_RINGING == state) {

        }

        if (TelephonyManager.CALL_STATE_OFFHOOK == state) {

        }

        if (TelephonyManager.CALL_STATE_IDLE == state) {

        }
    }
}

在你 onCreate() 添加:

PhoneCallListener phoneListener = new PhoneCallListener();
TelephonyManager telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(phoneListener,PhoneStateListener.LISTEN_CALL_STATE);
于 2012-09-29T09:25:11.710 回答