78.1.1+
Camera Initialization
TruvideoSdkCamera is the single class containing the methods required to work with the camera module these are
ActivityResultLauncher<TruvideoSdkCameraConfiguration>
: Launches the camera screen using theTruvideoSdkCameraContract
and handles the returned media results.Returns:
ActivityResultLauncher<TruvideoSdkCameraConfiguration>
: A launcher object that can be used to start the camera activity.
The result
parameter is a List<TruvideoSdkCameraMedia>
, containing media objects captured by the camera. The structure of TruvideoSdkCameraMedia
should be documented separately as it depends on the Truvideo SDK.
import com.truvideo.sdk.camera.TruvideoSdkCamera;
import com.truvideo.sdk.camera.model.TruvideoSdkCameraConfiguration;
import com.truvideo.sdk.camera.ui.activities.camera.TruvideoSdkCameraContract;
import com.truvideo.sdk.camera.model.TruvideoSdkCameraMedia;
import androidx.activity.result.ActivityResultLauncher;
public class YourActivity extends AppCompatActivity{
ActivityResultLauncher<TruvideoSdkCameraConfiguration> cameraScreenLauncher;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
cameraScreenLauncher = registerForActivityResult(
new TruvideoSdkCameraContract(),
result -> {
// Handle result
}
);
//...rest of your code
}
}
launch(truvideoSdkCameraConfiguration)
: This function is responsible for starting the camera view it takes TruvideoSdkCameraConfiguration as inputTruvideoSdkCameraConfiguration
: this is a data class that contains camera configuration data.
import com.truvideo.sdk.camera.model.TruvideoSdkCameraConfiguration;
import com.truvideo.sdk.camera.model.TruvideoSdkCameraFlashMode;
import com.truvideo.sdk.camera.model.TruvideoSdkCameraLensFacing;
import com.truvideo.sdk.camera.model.TruvideoSdkCameraMedia;
import com.truvideo.sdk.camera.model.TruvideoSdkCameraMode;
import com.truvideo.sdk.camera.model.TruvideoSdkCameraOrientation;
import com.truvideo.sdk.camera.model.TruvideoSdkCameraResolution;
public void openCamera(Context context) {
if (cameraScreenLauncher == null) return;
TruvideoSdkCameraInformation cameraInfo = TruvideoSdkCamera.getInstance().getInformation();
// you can choose the default camera lens facing
// options: Back, Front
TruvideoSdkCameraLensFacing lensFacing = TruvideoSdkCameraLensFacing.BACK;
// TruvideoSdkCameraLensFacing lensFacing = TruvideoSdkCameraLensFacing.FRONT;
// you can choose if the flash its enabled or not by default
TruvideoSdkCameraFlashMode flashMode = TruvideoSdkCameraFlashMode.OFF;
// TruvideoSdkCameraFlashMode flashMode = TruvideoSdkCameraFlashMode.ON;
TruvideoSdkCameraOrientation orientation = null;
// TruvideoSdkCameraOrientation orientation = TruvideoSdkCameraOrientation.PORTRAIT;
// TruvideoSdkCameraOrientation orientation = TruvideoSdkCameraOrientation.LANDSCAPE_LEFT;
// TruvideoSdkCameraOrientation orientation = TruvideoSdkCameraOrientation.LANDSCAPE_RIGHT;
// TruvideoSdkCameraOrientation orientation = TruvideoSdkCameraOrientation.PORTRAIT_REVERSE;
String outputPath = context.getFilesDir().getPath() + "/camera";
// You can decide the list of allowed resolutions for the front camera
// if you send an empty list, all the resolutions are allowed
List<TruvideoSdkCameraResolution> frontResolutions = new ArrayList<>();
if (cameraInfo.getFrontCamera() != null) {
// if you don't want to decide the list of allowed resolutions, you can send all the resolutions or an empty list
frontResolutions = cameraInfo.getFrontCamera().getResolutions();
//frontResolutions = new ArrayList<>();
// Example of how to allow only the one resolution
// List<TruvideoSdkCameraResolution> resolutions = new ArrayList<>();
// resolutions.add(cameraInfo.getFrontCamera().getResolutions().get(0));
// frontResolutions = resolutions;
}
// You can decide the default resolution for the front camera
TruvideoSdkCameraResolution frontResolution = null;
if (cameraInfo.getFrontCamera() != null) {
// Example of how tho pick the first resolution as the default one
List<TruvideoSdkCameraResolution> resolutions = cameraInfo.getFrontCamera().getResolutions();
if (!resolutions.isEmpty()) {
frontResolution = resolutions.get(0);
}
}
List<TruvideoSdkCameraResolution> backResolutions = new ArrayList<>();
TruvideoSdkCameraResolution backResolution = null;
// You can decide the mode of the camera
// Options: video and picture, video, picture
TruvideoSdkCameraMode mode = TruvideoSdkCameraMode.videoAndPicture();
// TruvideoSdkCameraMode mode = TruvideoSdkCameraMode.VIDEO;
// TruvideoSdkCameraMode mode = TruvideoSdkCameraMode.PICTURE;
TruvideoSdkCameraConfiguration configuration = new TruvideoSdkCameraConfiguration(
lensFacing,
flashMode,
orientation,
outputPath,
frontResolutions,
frontResolution,
backResolutions,
backResolution,
mode,
TruvideoSdkCameraImageFormat.JPEG, // image format
true, // videoStablizationEnabled
);
cameraScreenLauncher.launch(configuration);
}
Augmented Reality (AR)
This document explains how to use the AR camera from a contract in an Android application using the Truvideo SDK. It provides instructions on how to launch both the standard camera and the AR camera from an activity using the TruvideoSdkArCameraContract
.
Prerequisites
Ensure you have included the necessary Truvideo SDK dependencies in your project.
Steps to Implement AR Camera Call
Initial Project Setup
Ensure that your project is correctly configured with the following libraries:
Activity Result API
to handle camera interaction.Truvideo SDK libs, to enable camera functionalities.
Declare Camera Launchers
In your
Activity
where you want to launch the camera, define the launchers for both the regular camera and the AR camera.
class YourActivity: AppCompatActivity() {
var cameraARScreenLauncher : ActivityResultLauncher<TruvideoSdkCameraConfiguration>?=null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
cameraARScreenLauncher = registerForActivityResult(TruvideoSdkArCameraContract()) { result: List<TruvideoSdkCameraMedia> ->
// Handle result
}
//...rest of your code
}
}
Camera Configuration
Define the camera configuration using
TruvideoSdkCameraConfiguration
. In this example, we set a video and picture capture mode with specific constraints (max videos, photos, and duration limits).
var configuration: TruvideoSdkCameraConfiguration = TruvideoSdkCameraConfiguration(
outputPath = outputPath,
mode = TruvideoSdkCameraMode.videoAndPicture(
videoMaxCount = 10,
pictureMaxCount = 2,
durationLimit = 3 * 1000
)
)
Calling the Camera
Inside the UI, you can add buttons that launch both the regular camera and the AR camera. Here’s how you can open the AR camera when the user taps the corresponding button.
button.setOnClickListener {
cameraARScreenLauncher.launch(configuration)
}
This button will trigger the AR camera using the previously defined configuration.
AR Mode states
Inside the ARCamera module, we have 3 AR Mode States: Object (arrow), Ruler and Record. By default we will have an AR Cursor and the AR Mode RULER.
OBJECT: Allows the user to add a 3D Object on the AR Cursor, in this case an arrow.
RULER: Allows the user to meter with our AR Ruler a determined 3D space.
RECORD: Hiddens the AR Cursor so we can focus on the media recording.

AR Camera Validations
Inside the ARCamera module, we validate whether the device supports or has ARCore installed, in those case scenarios, we have 2 values that can return that information:
isAugmentedRealitySupported
: This property determines whether the device's hardware supports ARCore. It is essential to validate this before attempting any augmented reality operations, as trying to use ARCore on an unsupported device will result in runtime errors or unexpected behavior.isAugmentedRealityInstalled
: This property checks whether the ARCore services are installed on the device. Even if the device supports ARCore, it may not have the required services installed. By verifying this property, developers can avoid runtime issues by prompting users to install ARCore if necessary.
import com.truvideo.sdk.camera.TruvideoSdkCamera
...
val ARCoreSupported = TruvideoSdkCamera.isAugmentedRealitySupported
val ARCoreInstalled = TTruvideoSdkCamera.isAugmentedRealityInstalled
Final Result

AR Camera Limitations
During the development of AR experiences using ARCore, it's common to require control over the camera resolution — for high-quality recordings, image processing, or performance (low resolution videos with 720p). However, ARCore restricts direct control over the camera resolution during an AR session, which can lead to confusion or misaligned expectations among developers. ARCore internally does not allow the user to change the camera session if it's too low for ARCore (minimum currently on our tests was 1080p) or if the device itself does not allow it.
📚 Official References and Sources about limitations
ARCore CameraConfig Documentation Describes camera configuration options and limitations:
GitHub Issues in ARCore SDK The ARCore team has clarified that resolution control is not supported due to architectural constraints:
AR Camera Recommendations
Do not assume Camera2-like behavior when working with ARCore’s camera stream.
Avoid restarting the AR session solely to apply a different resolution — this often leads to crashes or resource leaks.
Always validate the selected
CameraConfig
, but understand that ARCore may internally override it to ensure tracking quality.
Scanner Camera Initialization
TruvideoSdkCameraScanner is the single class containing the methods required to work with the scanner module.
ActivityResultLauncher<TruvideoSdkCameraScannerConfiguration>: Launches the scanner screen using the
TruvideoSdkCameraScannerContract
and handles the scanned code result.Returns:
ActivityResultLauncher<TruvideoSdkCameraScannerConfiguration>
– A launcher object that can be used to start the scanner activity.Result Parameter: A
TruvideoSdkCameraScannerCode?
, which contains the scanned code data (e.g., QR code or barcode).Validation: You can implement custom validation logic by providing a
TruvideoSdkCameraScannerValidation
. The validator receives the scanned code and returns aTruvideoSdkCameraScannerValidationResult
to either accept or reject the scanned value.
class YourActivity: AppCompatActivity() {
var scannerScreenLauncher : ActivityResultLauncher<TruvideoSdkCameraScannerConfiguration>?=null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
scannerScreenLauncher = registerForActivityResult(TruvideoSdkCameraScannerContract()) { result: TruvideoSdkCameraScannerCode? ->
Log.d("TAG", "initScanner: $result")
// Handle result
}
openScanner(scannerScreenLauncher)
//...rest of your code
}
}
fun openScanner( cameraScreen: ActivityResultLauncher<TruvideoSdkCameraScannerConfiguration>?){
val scannerConfiguration = TruvideoSdkCameraScannerConfiguration(
validator = object : TruvideoSdkCameraScannerValidation {
override fun validate(code: TruvideoSdkCameraScannerCode): TruvideoSdkCameraScannerValidationResult {
Log.d("TAG", "validate: ${code.data}")
return TruvideoSdkCameraScannerValidationResult.success()
}
}
)
cameraScreen!!.launch(scannerConfiguration)
}
Entities
Preset
TruvideoSdkCameraConfiguration
is a public class that encapsulates the configuration parameters for the TruvideoSDK camera. It includes settings such as the lens facing direction (front or back), flash mode, video orientation, output path for saved content, preferred video codec, and camera mode. This structure allows developers to customize camera behavior and output format to suit specific application requirements
data class TruvideoSdkCameraConfiguration(
val lensFacing: TruvideoSdkCameraLensFacing = TruvideoSdkCameraLensFacing.BACK,
val flashMode: TruvideoSdkCameraFlashMode = TruvideoSdkCameraFlashMode.OFF,
val orientation: TruvideoSdkCameraOrientation? = null,
val outputPath: String = "",
val frontResolutions: List<TruvideoSdkCameraResolution> = listOf(),
val frontResolution: TruvideoSdkCameraResolution? = null,
val backResolutions: List<TruvideoSdkCameraResolution> = listOf(),
val backResolution: TruvideoSdkCameraResolution? = null,
val mode: TruvideoSdkCameraMode = TruvideoSdkCameraMode.videoAndPicture()
val imageFormat: TruvideoSdkCameraImageFormat = TruvideoSdkCameraImageFormat.JPEG,
val videoStabilizationEnabled: Boolean = true
)
Lens Facing
TruvideoSdkCameraLensFacing
enum represents the two possible directions of a camera lens: back or front.
enum class TruvideoSdkCameraLensFacing {
BACK,
FRONT;
val isBack: Boolean
get() {
return this == BACK
}
val isFront: Boolean
get() {
return this == FRONT
}
}
Flash Mode
TruvideoSdkCameraFlashMode
enum defines two flash modes: off and on, offering developers control over flash functionality during media capture.
enum class TruvideoSdkCameraFlashMode {
OFF,
ON;
val isOff: Boolean
get() {
return this == OFF
}
val isOn: Boolean
get() {
return this == ON
}
}
Orientation
TruvideoSdkCameraOrientation
enum offers four orientation choices: portrait, landscapeLeft, landscapeRight, and portraitReverse, enabling developers to define camera orientation preferences for media capture.
enum class TruvideoSdkCameraOrientation {
PORTRAIT,
LANDSCAPE_LEFT,
LANDSCAPE_RIGHT,
PORTRAIT_REVERSE;
}
Camera Mode
TruvideoSdkCameraMode
enum includes three modes: video and picture, video, and picture, enabling developers to specify whether the camera should capture both video and pictures, only video, or only pictures, respectively.
picture
configures capture of multiple pictures with an optional limit on picture count (null for no limit). Returns a TruvideoSdkCameraMediaMode instance.singlePicture
configures capture of one picture. Returns a TruvideoSdkCameraMediaMode instance.singleVideo
configures capture of one video with an optional duration limit (null for no limit). Returns a TruvideoSdkCameraMediaMode instance.singleVideoOrPicture
configures capture of either one video or one picture with an optional video duration limit (null for no limit). Returns a TruvideoSdkCameraMediaMode instance.video
configures capture of multiple videos with optional limits on video count and duration (null for no limit). Returns a TruvideoSdkCameraMediaMode instance.videoAndPicture
configures capture of videos and pictures with optional parameters: videoCount (maximum videos, null for no limit), pictureCount (maximum pictures, null for no limit), and videoDuration (maximum video duration in seconds, null for no limit). Returns the instance of TruvideoSdkCameraMediaMode.videoAndPicture
configures capture of videos and pictures with parameters: mediaCount (strict maximum combined videos and pictures) and videoDuration (maximum video duration in seconds, null for no limit). Returns a TruvideoSdkCameraMediaMode instance.
enum class TruvideoSdkCameraMode {
public final fun picture(): TruvideoSdkCameraMode
public final fun picture(maxCount: kotlin.Int?):TruvideoSdkCameraMode
public final fun singlePicture():TruvideoSdkCameraMode
public final fun singleVideo():TruvideoSdkCameraMode
public final fun singleVideo(durationLimit: kotlin.Int? ): TruvideoSdkCameraMode
public final fun singleVideoOrPicture(): TruvideoSdkCameraMode
public final fun singleVideoOrPicture(durationLimit: kotlin.Int? ): TruvideoSdkCameraMode
public final fun video(): TruvideoSdkCameraMode
public final fun video(maxCount: kotlin.Int? ): TruvideoSdkCameraMode
public final fun video(maxCount: kotlin.Int? , durationLimit: kotlin.Int? ): TruvideoSdkCameraMode
public final fun videoAndPicture(): TruvideoSdkCameraMode
public final fun videoAndPicture(durationLimit: kotlin.Int? ): TruvideoSdkCameraMode
public final fun videoAndPicture(maxCount: kotlin.Int? , durationLimit: kotlin.Int? ): TruvideoSdkCameraMode
public final fun videoAndPicture(videoMaxCount: kotlin.Int? , pictureMaxCount: kotlin.Int? , durationLimit: kotlin.Int? ): TruvideoSdkCameraMode
}
Video Resolution
TruvideoSdkCameraResolution
defines two camera resolution options: height and width, providing developers with choices for the resolution of video content within the TruvideoSDK.
data class TruvideoSdkCameraResolution(
val width: Int,
val height: Int
)
Image Format
TruvideoSdkCameraImageFormat defines the format of capture Image by default it is JPEG, while there are 2 options JPEG and PNG
enum class TruvideoSdkCameraImageFormat {
JPEG,
PNG;
}
Output Data
The result of the camera returns the list of TruvideoSdkCameraMedia
which contains the details about the video or photo capture which have these variables
createdAt
(Long): Unix timestamp (in milliseconds) indicating the exact time the media was captured.filePath
(String): Full path to the captured media file (image or video) on the device's storage.type
(TruvideoSdkCameraMediaType): Enumerated value specifying the media type (VIDEO or PICTURE).cameraLensFacing
(TruvideoSdkCameraLensFacing): An enumerated value indicating the camera lens that captured the media (FRONT or BACK).rotation
(TruvideoSdkCameraOrientation): Enumerated value representing the media's orientation (e.g., PORTRAIT, LANDSCAPE).resolution
(TruvideoSdkCameraResolution): Enumerated value specifying the media's resolution containing the value of height, width, and aspect ratio.duration
(Long): Applicable only for video media; represents the video's duration in milliseconds.
data class TruvideoSdkCameraMedia(
val id: String
val createdAt: Long,
val filePath: String,
val type: TruvideoSdkCameraMediaType,
val lensFacing: TruvideoSdkCameraLensFacing,
val orientation: TruvideoSdkCameraOrientation,
val resolution: TruvideoSdkCameraResolution,
val duration: Long,
)
Camera Events
The SDK communicates various camera-related events to consumers through a publisher that sends TruvideoSdkCameraEvent
objects containing details about the event, including its type and creation date.
Event Observer
To observe camera events, consumers can register an observer using the provided Observer class. The observer listens for events and logs details about them.
Example Usage :
public class YourActivity extends AppCompatActivity{
Observer<TruvideoSdkCameraEvent> observer = new Observer<TruvideoSdkCameraEvent>() {
@Override
public void onChanged(TruvideoSdkCameraEvent event) {
Log.d("TruvideoSdkCameraEvents", "Event type " + event.getType() + ": " + event.getData());
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Register observer
TruvideoSdkCamera.getEvents().observeForever(observer);
}
@Override
protected void onDestroy() {
super.onDestroy();
// Deregister observer
TruvideoSdkCamera.getEvents().removeObserver(observer);
}
}
Event Class: TruvideoSdkCameraEvent
TruvideoSdkCameraEvent
This class encapsulates the details of an event, including the event type, associated data, and the event's creation date.
Properties:
type:
TruvideoSdkCameraEventType
The type of event that occurred.data:
TruvideoSdkCameraEventData
The data associated with the event. This data can vary depending on the event type.createdAt:
Date
The date and time when the event was created.
class TruvideoSdkCameraEvent {
// Event type
val type: TruvideoSdkCameraEventType
val data: TruvideoSdkCameraEventData
// Event creation date
val createdAt: Date
}
Event Type Enum: TruvideoSdkCameraEventType
TruvideoSdkCameraEventType
The TruvideoSdkCameraEventType
enum defines the types of events that can be emitted by the Camera SDK.
Enum Values:
RecordingStarted Triggered when recording starts.
RecordingFinished Triggered when recording finishes.
RecordingPaused Triggered when recording is paused.
RecordingResumed Triggered when recording resumes.
PictureTaken Triggered when a picture is taken.
CameraFlipped Triggered when the camera is flipped between front and back.
ResolutionChanged Triggered when the camera resolution is changed.
FlashModeChanged Triggered when the flash mode is changed.
ZoomChanged Triggered when the zoom level is changed.
MediaDeleted Triggered when media is deleted.
MediaDiscard Triggered when media is discarded.
Continue Represents an event to continue clicked for saving photos and videos.
enum class TruvideoSdkCameraEventType{
RecordingStarted,
RecordingFinished,
RecordingPaused,
RecordingResumed,
PictureTaken,
CameraFlipped,
ResolutionChanged,
FlashModeChanged,
ZoomChanged,
MediaDeleted,
MediaDiscard,
Continue;
}
Last updated
Was this helpful?