How to know callee is answered the call (What is the phone state when he lift the call)

一世执手 提交于 2019-12-04 16:45:28

问题


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

Generally it has three states CALL_STATE_IDLE , CALL_STATE_OFFHOOK, CALL_STATE_RINGING.

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

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?


回答1:


The state will be OFF_HOOK

Device call state: Off-hook. At least one call exists that is dialing, active, or on hold, and no calls are ringing or waiting.

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



来源:https://stackoverflow.com/questions/11520590/how-to-know-callee-is-answered-the-call-what-is-the-phone-state-when-he-lift-th

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!