如何知道被叫应答呼叫(什么是手机状态,当他提起电话)当他、状态、电话、手机

2023-09-06 00:08:05 作者:颜值区总司令

我想知道如何当被叫方提起呼叫提醒。我已经使用 PhoneStateListener 以及的BroadcastReceiver

I am trying to know how to alert when the callee lifts the call. I have used PhoneStateListener along with BroadcastReceiver.

一般来说,有三种状态 CALL_STATE_IDLE,CALL_STATE_OFFHOOK,CALL_STATE_RINGING

Generally it has three states CALL_STATE_IDLE , CALL_STATE_OFFHOOK, CALL_STATE_RINGING.

CALL_STATE_OFFHOOK 时,呼叫连接状态被调用,上述三种状态的任何国家被称为后,被叫方回答 调用。

CALL_STATE_OFFHOOK state was calling when call is connecting, No state of the above three states was called after callee answered call.

下面是我的BroadcastReceiver。

Here is my BroadcastReceiver.

public class PhoneStateBroadcastReceiver extends BroadcastReceiver
{

   @Override
    public void onReceive(Context context, Intent intent)
    {

        TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        telephonyManager.listen(new CustomPhoneStateListener(context), PhoneStateListener.LISTEN_CALL_STATE);

    }

    public class CustomPhoneStateListener  extends PhoneStateListener
    {

        Context context; //Context to make Toast if required 
        ActivityManager activityManager;

        public CustomPhoneStateListener(Context context)
        {
            super();
            this.context = context;
        }

        @Override
        public void onCallStateChanged(int state, String incomingNumber) 
        {
            super.onCallStateChanged(state, incomingNumber);
            Log.v("PhoneStateBroadcastReceiver", "onCallStateChanged state"+state);


            switch (state) 
            {
            case TelephonyManager.CALL_STATE_IDLE:
               Toast.makeText(context, "=CALL_STATE_IDLE==", Toast.LENGTH_LONG).show();
             break;
            case TelephonyManager.CALL_STATE_OFFHOOK:
                Toast.makeText(context, "CALL_STATE_OFFHOOK", Toast.LENGTH_LONG).show();

                break;
            case TelephonyManager.CALL_STATE_RINGING:
                Toast.makeText(context, "CALL_STATE_RINGING", Toast.LENGTH_LONG).show();

                break;
            default:
                break;
            }
        }
      }
 }

我已经看到了一些应用录制语音通话时被接受。我想知道接受呼叫的状态。

I have seen some applications there are recording a voice when call was accepted. I want to know the state of accepting call.

有没有任何其他国家或听众知道什么时候被调用者响应号召?

Is there any other state or listener to know when the callee is answered the call?

推荐答案

该状态将是 OFF_HOOK

设备通话状态:摘机。至少有一个呼叫存在,即拨号,活动,或搁置,也没有电话振铃或等待。

您可以在此链接上看到   的http://developer.android.com/reference/android/telephony/TelephonyManager.html

You can see on this link: http://developer.android.com/reference/android/telephony/TelephonyManager.html