TruvideoSdkCamera is the single class containing the methods required to work with the camera module these are
ActivityResultLauncher<TruvideoSdkCameraConfiguration>: Launches the camera screen using the TruvideoSdkCameraContract 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.
Hint
The // Handle result comment should be replaced with actual code to process the captured media.
Consider adding error handling for cases where the camera activity is canceled or fails.
If the TruvideoSdkCameraConfiguration object has significant properties, provide more details about its purpose.
For better readability, consider using descriptive variable names instead of result.
importcom.truvideo.sdk.camera.TruvideoSdkCamera;importcom.truvideo.sdk.camera.model.TruvideoSdkCameraConfiguration;importcom.truvideo.sdk.camera.ui.activities.camera.TruvideoSdkCameraContract;importcom.truvideo.sdk.camera.model.TruvideoSdkCameraMedia;importandroidx.activity.result.ActivityResultLauncher;publicclassYourActivityextendsAppCompatActivity{ActivityResultLauncher<TruvideoSdkCameraConfiguration> cameraScreenLauncher;@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState); cameraScreenLauncher =registerForActivityResult(new TruvideoSdkCameraContract(), result ->{ // Handle result}); //...rest of your code}}
import com.truvideo.sdk.camera.TruvideoSdkCameraimport com.truvideo.sdk.camera.model.external.TruvideoSdkCameraConfigurationimport com.truvideo.sdk.camera.ui.activities.camera.TruvideoSdkCameraContractimport com.truvideo.sdk.camera.model.TruvideoSdkCameraMediaclassYourActivity: AppCompatActivity() {var cameraScreenLauncher : ActivityResultLauncher<TruvideoSdkCameraConfiguration>?=nulloverridefunonCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState) cameraScreenLauncher =registerForActivityResult(TruvideoSdkCameraContract()) { result: List<TruvideoSdkCameraMedia> ->// Handle result }//...rest of your code }}
launch(truvideoSdkCameraConfiguration): This function is responsible for starting the camera view it takes TruvideoSdkCameraConfiguration as input
TruvideoSdkCameraConfiguration: this is a data class that contains camera configuration data.
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.
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).
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.
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.
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:
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 a TruvideoSdkCameraScannerValidationResult to either accept or reject the scanned value.
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
Lens Facing
TruvideoSdkCameraLensFacing enum represents the two possible directions of a camera lens: back or front.
Flash Mode
TruvideoSdkCameraFlashMode enum defines two flash modes: off and on, offering developers control over flash functionality during media capture.
Orientation
TruvideoSdkCameraOrientation enum offers four orientation choices: portrait, landscapeLeft, landscapeRight, and portraitReverse, enabling developers to define camera orientation preferences for media capture.
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.
Image configures capture of multiple pictures with an optional limit on maxCount (null for no limit). Returns a TruvideoSdkCameraMode instance.
SingleImage configures capture of one picture. Returns a TruvideoSdkCameraMode instance.
singleVideo configures capture of one video with an optional duration limit (null for no limit). Returns a TruvideoSdkCameraMode instance.
singleVideoOrPicture configures capture of either one video or one picture with an optional video duration limit (null for no limit). Returns a TruvideoSdkCameraMode instance.
video configures capture of multiple videos with optional limits on video count and duration (null for no limit). Returns a TruvideoSdkCameraMode 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 TruvideoSdkCameraMode.
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 TruvideoSdkCameraMode instance.
Video Resolution
TruvideoSdkCameraResolution defines two camera resolution options: height and width, providing developers with choices for the resolution of video content within the TruvideoSDK.
Image Format
TruvideoSdkCameraImageFormat defines the format of capture Image by default it is JPEG, while there are 2 options JPEG and 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.
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 :
Event Class: 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.
Event Type Enum: 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.
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);
}
import com.truvideo.sdk.camera.model.external.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
fun openCamera() {
// Start camera with configuration
// if camera is not available, it will return null
if (cameraScreenLauncher == null) return;
// Get camera information
val cameraInfo = TruvideoSdkCamera.getInformation()
// you can choose the default camera lens facing
// options: Back, Front
val lensFacing = TruvideoSdkCameraLensFacing.BACK
// TruvideoSdkCameraLensFacing lensFacing = TruvideoSdkCameraLensFacing.FRONT;
// You can choose if the flash is on or off by default
val flashMode = TruvideoSdkCameraFlashMode.OFF
// val flashMode = TruvideoSdkCameraFlashMode.ON
// You can choose the camera orientation
// Options: null, Portrait, LandscapeLeft, LandscapeRight, PortraitReverse
// Null means any orientation
val orientation: TruvideoSdkCameraOrientation? = null
// TruvideoSdkCameraOrientation orientation = TruvideoSdkCameraOrientation.PORTRAIT;
// TruvideoSdkCameraOrientation orientation = TruvideoSdkCameraOrientation.LANDSCAPE_LEFT;
// TruvideoSdkCameraOrientation orientation = TruvideoSdkCameraOrientation.LANDSCAPE_RIGHT;
// TruvideoSdkCameraOrientation orientation = TruvideoSdkCameraOrientation.PORTRAIT_REVERSE;
// You can choose where the files will be saved
val outputPath = context.filesDir.path + "/camera"
// You can decide the list of allowed resolutions for the front camera
// if you send an empty list, all the resolutions are allowed
var frontResolutions: List<TruvideoSdkCameraResolution> = ArrayList()
if (cameraInfo.frontCamera != 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.frontCamera!!.resolutions
//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
var frontResolution: TruvideoSdkCameraResolution? = null
if (cameraInfo.frontCamera != null) {
// Example of how tho pick the first resolution as the default one
val resolutions = cameraInfo.frontCamera!!.resolutions
if (resolutions.isNotEmpty()) {
frontResolution = resolutions[0]
}
}
val backResolutions: List<TruvideoSdkCameraResolution> = ArrayList()
val backResolution: TruvideoSdkCameraResolution? = null
// You can decide the mode of the camera
// Options: video and picture, video, picture
val mode = TruvideoSdkCameraMode.VideoAndImage()
// TruvideoSdkCameraMode mode = TruvideoSdkCameraMode.Video();
// TruvideoSdkCameraMode mode = TruvideoSdkCameraMode.Image();
val configuration = TruvideoSdkCameraConfiguration(
lensFacing = lensFacing,
flashMode = flashMode,
orientation = orientation,
outputPath = outputPath,
frontResolutions = frontResolutions,
frontResolution = frontResolution,
backResolutions = backResolutions,
backResolution = backResolution,
mode = mode,
imageFormat = TruvideoSdkCameraImageFormat.JPEG,// TruvideoSdkCameraImageFormat.PNG
videoStabilizationEnabled = true
)
cameraScreenLauncher.launch(configuration)
}
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
}
}
import com.truvideo.sdk.camera.TruvideoSdkCamera
...
val ARCoreSupported = TruvideoSdkCamera.isAugmentedRealitySupported
val ARCoreInstalled = TTruvideoSdkCamera.isAugmentedRealityInstalled
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)
}
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
)
enum class TruvideoSdkCameraLensFacing {
BACK,
FRONT;
val isBack: Boolean
get() {
return this == BACK
}
val isFront: Boolean
get() {
return this == FRONT
}
}
enum class TruvideoSdkCameraFlashMode {
OFF,
ON;
val isOff: Boolean
get() {
return this == OFF
}
val isOn: Boolean
get() {
return this == ON
}
}
enum class TruvideoSdkCameraOrientation {
PORTRAIT,
LANDSCAPE_LEFT,
LANDSCAPE_RIGHT,
PORTRAIT_REVERSE;
}
enum class TruvideoSdkCameraMode {
@Serializable
data class Image @JvmOverloads constructor(
val maxCount: Int? = null
) : TruvideoSdkCameraMode()
@Serializable
data class Video @JvmOverloads constructor(
val maxCount: Int? = null,
val durationLimit: Long? = null,
) : TruvideoSdkCameraMode()
@Serializable
data class VideoAndImage @JvmOverloads constructor(
val limit: Limit? = null,
val videoDurationLimit: Long? = null
) : TruvideoSdkCameraMode() {
@Serializable
sealed class Limit {
@Serializable
data class ByTotal(val maxMediaCount: Int) : Limit()
@Serializable
data class ByType(
val maxVideoCount: Int? = null,
val maxImageCount: Int? = null
) : Limit()
}
}
@Serializable
data class SingleImage(
override val autoClose: Boolean = false
) : TruvideoSdkCameraMode()
@Serializable
data class SingleVideo @JvmOverloads constructor(
override val autoClose: Boolean = false,
val durationLimit: Long? = null
) : TruvideoSdkCameraMode()
@Serializable
data class SingleVideoOrImage @JvmOverloads constructor(
override val autoClose: Boolean = false,
val videoDurationLimit: Long? = null
) : TruvideoSdkCameraMode()
}
data class TruvideoSdkCameraResolution(
val width: Int,
val height: Int
)
enum class TruvideoSdkCameraImageFormat {
JPEG,
PNG;
}
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,
)
class TruvideoSdkCameraEvent {
// Event type
val type: TruvideoSdkCameraEventType
val data: TruvideoSdkCameraEventData
// Event creation date
val createdAt: Date
}