如何知道被叫接听来电(什么是手机状态,当他提起电话)(How to know callee is a

2019-07-30 11:10发布

我想知道如何当被叫方提起呼叫警报。 我已经使用PhoneStateListener连同BroadcastReceiver

一般来说,有三种状态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;
            }
        }
      }
 }

我见过一些应用录制语音通话时被接受。 我想知道接受呼叫的状态。

是否有任何其他国家或侦听器时被调用者响应号召,知道吗?

Answer 1:

国家将OFF_HOOK

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

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



文章来源: How to know callee is answered the call (What is the phone state when he lift the call)