Search code examples
androidphone-call

Handling incoming calls in Android


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 them.

Any ideas?


Solution

  • Just extend your class to PhoneStateListener and override onCallStateChanged method. Sample code:

    class myCallListener extends PhoneStateListener{
    
            @Override
            public void onCallStateChanged(int state, String incomingNumber) {
                // TODO Auto-generated method stub
                switch (state) {
                case TelephonyManager.CALL_STATE_RINGING:
                        // your logic here
                    break;
    
                default:
                    break;
                }
    
                super.onCallStateChanged(state, incomingNumber);
    
            }
        }