Reputation: 2202
How can I get an Intent to my register BroadcastReceiver, when device starts call and when ends call? It doesn't matter if it is an incoming call or an outgoing call. I only need to get Intent every time when device starts its call and when ends its call.
Upvotes: 0
Views: 102
Reputation: 1035
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) {
}
}
}
in you onCreate() add:
PhoneCallListener phoneListener = new PhoneCallListener();
TelephonyManager telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(phoneListener,PhoneStateListener.LISTEN_CALL_STATE);
Upvotes: 1