views:

73

answers:

1

I want to show a notification when a call is active.
I have done the first easy part. Notification starts when my call intent starts.
Now to the tricky part, how can I tell my Notification that the call has ended?

+1  A: 

You need to register a PhoneStateListener on the TelephonyManager.

TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);

PhoneStateListener listener = new PhoneStateListener() {
    @Override
    public void onCallStateChanged(int state, String incomingNumber) {
        if (state == TelephonyManager.CALL_STATE_IDLE) {
            // hangup    
        }
    } 
};

tm.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE);

To unregister your PhoneStateListener:

tm.listen(phoneListener, PhoneStateListener.LISTEN_NONE);
Schildmeijer
which state is the "hang up state" . Can only see STATE_RINGING, STATE_OFFHOOK, STATE_IDLE
f0rz
You start listening for the STATE_IDLE after a call has been initiated that will indicate that the call has ended
Donal Rafferty