Handling incoming calls in Android

后端 未结 2 1803
我在风中等你
我在风中等你 2021-01-26 13:20

I want to handle incoming call in Android.
Actually I want to set a time duration in which if my cell phone receive any call then automatically a message send to each of the

2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-26 13:58

    You need to declare PhoneStateListener in your Activity or Service:

    PhoneStateListener phoneStateListener = new PhoneStateListener() {
        @Override
        public void onCallStateChanged(int state, String incomingNumber) {
            if (state == TelephonyManager.CALL_STATE_RINGING) {
                ....
            } else if(state == TelephonyManager.CALL_STATE_IDLE) {
                ....
            } else if(state == TelephonyManager.CALL_STATE_OFFHOOK) {
                ....
            }
            super.onCallStateChanged(state, incomingNumber);
        }
    };
    

    And add following permission to AndroidManifest.xml:

    
    

    Hope this helps.

提交回复
热议问题