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
Solution 1:
Just extend your class to PhoneStateListener
and override onCallStateChanged
method. Sample code:
classmyCallListenerextendsPhoneStateListener{
@OverridepublicvoidonCallStateChanged(int state, String incomingNumber) {
// TODO Auto-generated method stubswitch (state) {
case TelephonyManager.CALL_STATE_RINGING:
// your logic herebreak;
default:
break;
}
super.onCallStateChanged(state, incomingNumber);
}
}
Solution 2:
You need to declare PhoneStateListener
in your Activity
or Service
:
PhoneStateListenerphoneStateListener=newPhoneStateListener() {
@OverridepublicvoidonCallStateChanged(int state, String incomingNumber) {
if (state == TelephonyManager.CALL_STATE_RINGING) {
....
} elseif(state == TelephonyManager.CALL_STATE_IDLE) {
....
} elseif(state == TelephonyManager.CALL_STATE_OFFHOOK) {
....
}
super.onCallStateChanged(state, incomingNumber);
}
};
And add following permission to AndroidManifest.xml
:
<uses-permissionandroid:name="android.permission.READ_PHONE_STATE" />
Hope this helps.
Post a Comment for "Handling Incoming Calls In Android"