20

我想知道如何在被叫方拨打电话时发出警报。我PhoneStateListenerBroadcastReceiver.

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

CALL_STATE_OFFHOOK通话接通时状态为通话状态,被叫接听后未调用上述三种状态。

这是我的广播接收器。

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;
            }
        }
      }
 }

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

是否有任何其他状态或侦听器知道被叫方何时接听电话?

4

1 回答 1

6

状态将为OFF_HOOK

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

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

于 2012-07-18T07:52:00.607 回答