5

Possible Duplicate:
Detect if an outgoing call has been answered

How can I know the moment when the person I call "picks up" his phone?

Community
  • 1
  • 1
Slot
  • 1,006
  • 2
  • 13
  • 27

1 Answers1

-1

As far as Android's telephony manager is concerned you cannot detect programmatically whether your call has been answered or not.

But for incoming calls it is possible, using PhoneStateListener. When YOU 'pick up' the phone, the state changes to CALL_STATE_OFFHOOK.

TelephonyManager tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
tm.listen(mPhoneListener, PhoneStateListener.LISTEN_CALL_STATE);

private PhoneStateListener mPhoneListener = new PhoneStateListener() {
    public void onCallStateChanged(int state, String incomingNumber) {
        try {
            switch (state) {
            case TelephonyManager.CALL_STATE_RINGING:
                // do something...
                break;

            case TelephonyManager.CALL_STATE_OFFHOOK:
                // you picked up the phone
                break;

            case TelephonyManager.CALL_STATE_IDLE:
                // do something...
                break;
            default:
                Log.d(TAG, "Unknown phone state=" + state);
            }
        } catch (RemoteException e) {}
    } 
};
Sergio
  • 640
  • 6
  • 23
  • Thanks you very much for your rapid and accurate response. Have a good day ! – Slot Oct 28 '11 at 13:55
  • 21
    Wrong CALL_STATE_OFFHOOK will be set immediately when the number is dialed and NOT when the person picks up the phone. – Johann Mar 05 '13 at 14:15
  • Is there any way to detect this for OUTGOING calls? – Diego Mar 12 '13 at 23:43
  • 2
    as AndroidDev said, with an out going call the state will be changed to OFFHOOK immediately. – Jonny May 26 '13 at 14:53
  • 1
    this doesn't work for outgoing calls. only for incoming calls. did you find any way to achieve it for outgoing calls? maybe by polling or using reflection on CallManager : http://grepcode.com/file_/repository.grepcode.com/java/ext/com.google.android/android/2.3.3_r1/com/android/internal/telephony/CallManager.java/?v=source ? – android developer Oct 01 '13 at 13:58
  • I edited it for clarity. It is possible only for incoming calls, as it has been mentioned. – Sergio Jan 31 '18 at 11:48