0

I'm trying to figure out how to be notified when a call is disconnected - both incoming and outgoing. the intent is to launch something on call disconnect.

I looked at the telephnyManager page and i can see getCallState(), but looking at all the constants, i don't see anything like what i'm looking.

I'm guessing i need to set up a broadcast receiver - i'm just not sure what i'm listening to...

Thanks for helping!!

raingod
  • 1,377
  • 1
  • 11
  • 24

1 Answers1

-1

in case someone is looking for the answer, here's the code (you never know when that link is gonna die!). This is not the complete code, but it's the code that will listen to a call change. What I didn't get when reading the documentation the first time was that getting a CALL_STATE_IDLE response, means that the connection that was there before is now idle - i.e., the call has been disconnected.

import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;

private class ListenToPhoneState extends PhoneStateListener {

        public void onCallStateChanged(int state, String incomingNumber) {
            Log.i("telephony-example", "State changed: " + stateName(state));
        }

        String stateName(int state) {
            switch (state) {
                case TelephonyManager.CALL_STATE_IDLE: return "Idle";
                case TelephonyManager.CALL_STATE_OFFHOOK: return "Off hook";
                case TelephonyManager.CALL_STATE_RINGING: return "Ringing";
            }
            return Integer.toString(state);
        }
    }
raingod
  • 1,377
  • 1
  • 11
  • 24