如何知道被叫人拿起电话的那一刻

时间:2011-10-28 13:13:48

标签: android

  

可能重复:
  Detect if an outgoing call has been answered

我怎么知道我打电话的人“拿起”他的电话的那一刻?

1 个答案:

答案 0 :(得分:-1)

就Android的电话管理员而言,无法以编程方式检测您的通话是否已被接听。

但是对于来电,可以使用PhoneStateListener。当您“拿起”手机时,状态会变为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) {}
    } 
};