如何知道被叫方接听电话(他解除电话时的电话状态是什么)

时间:2012-07-17 10:26:33

标签: android telephonymanager phone-call

我想知道当被叫者举起电话时如何提醒。我已使用PhoneStateListenerBroadcastReceiver

通常它有三种状态CALL_STATE_IDLE , CALL_STATE_OFFHOOK, CALL_STATE_RINGING

当呼叫连接时,

CALL_STATE_OFFHOOK状态正在呼叫,在被呼叫者应答之后,没有呼叫上述三种状态的状态 调用

这是我的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;
            }
        }
      }
 }

我已经看到一些应用程序在接听电话时录制了一个声音。我想知道接听电话的状态。

是否还有其他州或听众知道被叫方接听电话的时间?

1 个答案:

答案 0 :(得分:6)

州将 OFF_HOOK

设备呼叫状态:摘机。至少存在一个拨号,活动或保持的呼叫,并且没有呼叫振铃或等待。

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