Android

更新时间:
复制 MD 格式

The RTC software development kit (SDK) provides features for device detection and management. You can check whether your hardware devices are working correctly before you join a channel. This topic describes the methods used for device detection and management.

Feature description

The RTC SDK provides internal methods to detect and manage devices. For example, you can query device information, check if the camera is working correctly, test audio recording and playback, set the camera direction, or switch between audio devices such as the microphone and speaker.

Implementation

The following are common methods for device detection and management. For more information, see the AliRtcEngine interface.

  • getCurrentCameraDirection: Returns the current camera direction.
    public abstract AliRTCCameraDirection getCurrentCameraDirection();
    Return value
    • CAMERA_REAR(0): The rear-facing camera.
    • CAMERA_FRONT(1): The front-facing camera.
    • CAMERA_INVALID(-1): Invalid.
    Note Call this method after the camera is turned on. Otherwise, CAMERA_INVALID(-1) is returned.
  • isCameraOn: Checks if the camera is on.
    public abstract boolean isCameraOn();
    Return value

    true: The camera is on. false: The camera is off.

  • isSpeakerOn: Checks whether the current audio output is the earpiece or the speaker.
    public abstract boolean isSpeakerOn();
    Return value

    true: The speaker. false: The earpiece.

  • switchCamera: Switches between the front and rear cameras. The default camera is the front-facing camera.
    public abstract int switchCamera();
    Return value

    0: The method call is successful. Other values indicate that the method call failed.

  • setCameraZoom: Sets the camera zoom ratio.
    public abstract int setCameraZoom(float zoom);
    Parameter description
    ParameterTypeDescription
    zoomfloatThe zoom level. The default value is 1.0.
    Return value

    0: The method call is successful. Other values indicate that the method call failed.

  • setCameraFlash: Sets whether to turn on the camera flash.
    public abstract int setCameraFlash(boolean flash);
    Parameter description
    ParameterTypeDescription
    flashbooleanSpecifies whether to turn on the camera flash. Valid values:
    • true: Enabled.
    • false (default): shutdown.
    Return value

    0: The method call is successful. Other values indicate that the method call failed.

  • setCameraAutoFocusFaceModeEnabled: Enables or disables face autofocus for the camera.
    public abstract boolean setCameraAutoFocusFaceModeEnabled(boolean enable);
    Parameter description
    ParameterTypeDescription
    enablebooleanSpecifies whether to enable face autofocus for the camera. Valid values:
    • true: Enabled.
    • false (default): Disabled.
    Return value

    true: The method call was successful. false: The method call failed.

  • enableSpeakerphone: Sets the audio output to the speaker or the earpiece.
    public abstract int enableSpeakerphone(boolean enable);
    Parameter description
    ParameterTypeDescription
    enablebooleanSpecifies whether to use the earpiece or the speaker for audio output. Valid values:
    • true (default): Speaker mode.
    • false: Earpiece mode.
    Return value

    0: The method call is successful. Other values indicate that the method call failed.