AKStream.Next · 文档中心

Android native RTC SDK method reference

Android native RTC SDK method reference

Applies to the AAR delivered with the matching version. AkNativeRtcClient owns signaling, separate WHIP/WHEP media, the device session, reconnect, and cleanup. Your Activity/Fragment owns controls, layout, camera/microphone permission, MediaProjection consent, and lifecycle. Construct it with Context, a local SurfaceViewRenderer, and Listener; call close() when finished. Follow the Android integration walkthrough first.

AkNativeRtcClient rtc = new AkNativeRtcClient(getApplicationContext(), localRenderer, listener);
rtc.setInitialMediaEnabled(false, false);
rtc.joinWithAccessTicket(serverUrl, roomId, accessTicket, null);

serverUrl must be an HTTPS origin trusted by the phone; the Mac's 127.0.0.1 is not the phone's server. The ticket is consumed once. The SDK manages the device token and never needs the ZLM secret.

Session, identity, and recording

Method Input Result Edge case
AkNativeRtcClient(context, localRenderer, listener) App context, local renderer, callbacks Client object SDK initializes the renderer. Do not create multiple active clients for one Activity.
joinWithAccessTicket(serverUrl, roomId, accessTicket, passcode) Service, room, one-use ticket, optional passcode onJoined(participantId) or error Waiting for admission is not capture permission. OS or network failure is not a successful join.
createMeeting(settings, creator, callback) JSON settings, business-backend creator, result callback Room/ticket or failure Your backend authenticates the user; retry the same settings with the idempotency key.
listMembers() None onMembers(JSONArray) Refresh after disconnect, device replacement, or host transfer.
getParticipantId() / getCapabilities() / getRole() None Current participant ID, grants, role These may change on rejoin; old UI state cannot bypass server checks.
performRoomAction(action, payload, callback) Allowlisted action, JSON fields, RoomCallback success or httpFailure/failure Keep HTTP status separate from generic failure. Unknown actions are rejected by the SDK.
startContinuousRecording(callback) / stopContinuousRecording(recordingId, callback) / getContinuousRecording(callback) Run ID required for stop JSON state or no active run Only current host starts/stops; Stopping is not downloadable. Subscribe to onContinuousRecordingChanged.
leave() / close() None onLeft() / disposed object Leave this device and release threads/media. Do not reuse a kicked device's old ticket.
listDemoRooms(baseUrl) / createDemoMeeting(...) / issueDemoAccessTicket(...) Isolated-test options Demo callbacks/results Test-only; production uses tickets from your backend.

RoomCallback.httpFailure(RtcHttpException) retains HTTP status and an optional retryable flag. A missing flag means unknown. On 401, obtain new authentication; 403 means role, device, or grant denied, not a reason to loop retries. onState is informational and does not replace the result callback.

Camera, microphone, and screen

Method Input Result Edge case
setInitialMediaEnabled(microphone, camera) / setInitialMicrophoneEnabled(enabled) Booleans Initial join intent Set before join. Does not bypass OS permission.
hasLocalMicrophone() / hasLocalCamera() / isMicrophoneEnabled() / isCameraEnabled() None Device availability and effective switches Available hardware is not a publication grant.
setMicrophoneEnabled(enabled) / setCameraEnabled(enabled) Boolean Async local-track change Confirm with onLocalMediaState and remote reception. Host revocation or network loss may prevent publication.
setCameraForeground(foreground) Activity foreground state Capture lifecycle adjustment Respect Android background capture rules; recover eligible tracks on return.
listCameras() / switchCamera(cameraId) Camera ID CameraDevice list / onCameraChanged frontFacing distinguishes cameras. IDs can change after replug.
getInputDevices() / getAudioRouter() None Input selector and audio-route controller Show real device/route state, including Bluetooth changes.
startScreenShare(permission, width, height) / stopScreenShare() User-approved MediaProjection Intent, size onScreenSharingChanged Host must obtain system consent first. Screen is a separate publication and ends on consent revocation.
attachScreenSession(...) / updateScreenSessionToken(token) Trusted same-app screen-service context Updated screen publisher identity Never log or forward this short-lived credential across apps.
getSupportedVideoModes() / getEndpointInfo() None Mode JSONArray / device-info JSONObject Candidate modes are not proof of actual frame size; check media stats.

Remote media, collaboration, and diagnostics

Method Input Result Edge case
getVideoPresentation() None Local display transform controller Mirroring/rotation changes rendering, not source media or recording.
applyVideoTransform(renderer, transform) SurfaceViewRenderer, mirror/flip/rotation Static renderer helper Applies local presentation on capable renderers; a plain renderer may not support every transform.
participantForPublication(publicationId) Publication ID Participant ID or null Do not collapse a member's multiple streams/devices by display name.
getActiveSpeakerIds() / setRemoteAudioVolume(publicationId, volume) Publication ID, 0–1 volume Speaker snapshot / local volume Activity detection, not speaker authentication. Volume does not mute the remote sender.
sendChatMessage(text, targetParticipantId) / uploadAttachment(...) Text/file and optional direct-message target Chat/attachment event Direct attachments are private; final upload rechecks device rights.
downloadAttachment(...) / copyAttachmentTo(...) / downloadWhiteboardImage(...) Authorized attachment or ID; callback/output stream Bytes or failure Do not expose server file paths. Stream large files.
uploadWhiteboardImage(uri, callback) Local image URI Whiteboard material Uploading a material does not draw an object; a board event is still needed. Revocation may reject final commit.
sendHandRaised(raised) / sendReaction(reaction) Boolean or supported reaction Meeting event Neither grants publishing rights.

Key Listener events: onRemoteVideo/onRemoteVideoRemoved and audio equivalents manage each view; onLocalMediaState and onMediaPermissionChanged drive controls; onCapabilitiesChanged drives host UI; onWhiteboardEvent/onChatMessage drive collaboration; onContinuousRecordingChanged drives the recording indicator; onHttpError retains status; onLeft ends cleanup. Do not apply events from a prior device session to a new one.

The post-meeting AkRtcArchiveClient is documented in archive methods. A compiling AAR is not proof an older installed APK was updated; verify real bidirectional frames and sound on the target device.