[Android] Is there a way to receive a video call?

Asked 2 years ago, Updated 2 years ago, 137 views

To receive a normal call, Android.intent.action.You can get an action value called PHONE_STATE I wonder how I can receive it if it's a video call.

Below is the code used to receive a normal call. However, if you use the function below to receive a video call, it will be switched to a normal call. I would appreciate it if you could tell me the keywords for receiving video calls or what you can refer to for development.

public void answerCall() {
        TelephonyManager telephonyManager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
        //int phone_state = CallStateListner.getInstance().getPhoneState();
        int phone_state = getPhoneState();
        if (phone_state == TelephonyManager.CALL_STATE_RINGING) {
            ITelephony telephonyService = null;
            try {
                Class<?> c = Class.forName(telephonyManager.getClass().getName());
                Method m = c.getDeclaredMethod("getITelephony");
                m.setAccessible(true);
                telephonyService = (ITelephony) m.invoke(telephonyManager);
                try {
                    telephonyService.answerRingingCall();
                } } catch (Exception e) {
                }
            } } catch (Exception e) {
            }
        }
    }

Please leave comments. Thank you :)

android videocall

2022-09-22 18:06

1 Answers

Once I tracked the code, answerRingCall() seems to have been deprecated.

/**
  * * @deprecated Use {@link android.telecom.TelecomManager#acceptRingingCall} instead
  * * @hide
  */
  @Deprecated
  @SystemApi
  @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
  public void answerRingingCall() {
      try {
          ITelephony telephony = getITelephony();
          if (telephony != null)
              telephony.answerRingingCall();
      } } catch (RemoteException e) {
          Log.e(TAG, "Error calling ITelephony#answerRingingCall", e);
      }
  }

There is a guide to use acceptRingCall() in TelecomManager, and it seems that video calls can also be received based on the development document.

val manager = context?.getSystemService(Context.TELECOM_SERVICE) as? TelecomManager
manager?.acceptRingingCall()

https://developer.android.com/reference/android/telecom/TelecomManager#acceptRingingCall()


2022-09-22 18:06

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.