0

I have used TelephonyManager.CALL_STATE_OFFHOOK but unfortunately it gets called every time I touch the call button, i.e before the call is actually made.

my code:

public void onReceive(Context context, Intent intent) {
        this.context = context;
        listener = new CallStateListener();

        if(intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL")){
            Log.e("Aditya", "Broadcast listner");
            //Currently no use
        }
        TelephonyManager tm = (TelephonyManager) context.getSystemService(context.TELEPHONY_SERVICE);
        tm.listen(listener,PhoneStateListener.LISTEN_CALL_STATE);
    }

public class CallStateListener extends PhoneStateListener {
        int lastState = TelephonyManager.CALL_STATE_IDLE;
        @Override
        public void onCallStateChanged(int state, String incomingNumber) {
            switch (state) {
            case TelephonyManager.CALL_STATE_RINGING:
                // called when someone is ringing to this phone
                Toast.makeText(context,"Pioneer Contacts+ Updated",Toast.LENGTH_LONG).show();
                Log.e("Aditya", "ringing");
                break;

            case TelephonyManager.CALL_STATE_OFFHOOK:
                Toast.makeText(context,"Pioneer Contacts+ Updated",Toast.LENGTH_LONG).show();
                Log.e("Aditya", "offhook");
                break;
            }
        }
    }

The Log Log.e("Aditya", "offhook"); gets printed before the call gets connected. I want to appear it after the call is disconnected.

Shiva Saurabh
  • 1,281
  • 2
  • 25
  • 47
donison24x7
  • 304
  • 1
  • 15
  • Off-hook doesn't mean that the call has ended. The documentation describes it as _"At least one call exists that is dialing, active, or on hold"_. Think of old traditional phones where the handset would rest on a switch until you lift it to either make or answer a call. While lifted from the switch, the handset would be "off-hook". – Michael Apr 10 '14 at 11:45
  • see [this](http://stackoverflow.com/questions/5869269/how-to-get-call-end-event-in-android-app) and also see [link](http://stackoverflow.com/questions/5497061/detecting-outgoing-call-and-call-hangup-event-in-android) – user3355820 Apr 10 '14 at 11:53
  • @Michael ...I understand it's meaning. What I want is the 'HANG UP' event.. – donison24x7 Apr 10 '14 at 12:02

0 Answers0