Session

public class Session

Manages AR system state and handles the session lifecycle. This class is the main entry point to the ARCore API. This class allows the user to create a session, configure it, start or stop it and, most importantly, receive frames that allow access to camera image and device pose.

Important:

Before creating a Session, you must first verify that ARCore is installed and up to date. If ARCore isn't installed, then session creation will fail and any subsequent installation or upgrade of ARCore will require an app restart, and might cause Android to kill the app. You can verify ARCore is installed and up to date by:

This class owns a significant amount of native heap memory. When the AR session is no longer needed, call close() to release native resources. If your app contains a single AR-enabled activity, it is recommended that you call close() from the activity's onDestroy method. Failure to close the session explicitly may cause your app to run out of native memory and crash.

Nested Classes

enum Session.Feature Fundamental session features that can be requested using Session.Session(Context, Set)
enum Session.FeatureMapQuality Indicates the quality of the visual features seen by ARCore in the preceding few seconds from a given camera Pose

Public Constructors

Session(Context context)
Creates a new ARCore session.
Session(Context context, Set<Session.Feature> features)
Creates a new ARCore session requesting additional features.

Public Methods

VpsAvailabilityFuture
checkVpsAvailabilityAsync(double latitude, double longitude, Consumer<VpsAvailability> callback)
Gets the availability of the Visual Positioning System (VPS) at a specified horizontal position.
void
close()
Releases resources (a significant amount of native heap memory) used by an ARCore session.
void
configure(Config config)
Configures the session and verifies that the enabled features in the specified session config are supported with the currently set camera config.
Anchor
createAnchor(Pose pose)
Defines a tracked location in the physical world.
Session.FeatureMapQuality
estimateFeatureMapQualityForHosting(Pose pose)
Estimates the quality of the visual features seen by ARCore in the preceding few seconds and visible from the provided camera pose.
Collection<Anchor>
getAllAnchors()
Returns all known anchors, including those not currently tracked.
<T extends Trackable> Collection<T>
getAllTrackables(Class<T> filterType)
Returns the list of all known trackables.
CameraConfig
getCameraConfig()
Gets the current camera config used by the session.
void
getConfig(Config configToFill)
Similar to getConfig(), but takes a config object to fill.
Config
getConfig()
Gets the current config.
Earth
getEarth()
Returns the Earth object for the session.
PlaybackStatus
getPlaybackStatus()
Returns the current playback status.
RecordingStatus
getRecordingStatus()
Returns the current recording status.
SharedCamera
getSharedCamera()
Gets the SharedCamera object if the session was created for camera sharing using Session.Feature.SHARED_CAMERA.
List<CameraConfig>
getSupportedCameraConfigs()
This method is deprecated. Please use instead: getSupportedCameraConfigs(CameraConfigFilter).
List<CameraConfig>
getSupportedCameraConfigs(CameraConfigFilter cameraConfigFilter)
Gets the list of supported camera configs that satisfy the provided filter settings.
Anchor
hostCloudAnchor(Anchor anchor)
This method is deprecated. Use hostCloudAnchorAsync(Anchor, int, BiConsumer) with ttlDays=1 instead.
HostCloudAnchorFuture
hostCloudAnchorAsync(Anchor anchor, int ttlDays, BiConsumer<StringAnchor.CloudAnchorState> callback)
Uses the pose and other data from anchor to host a new Cloud Anchor.
Anchor
hostCloudAnchorWithTtl(Anchor anchor, int ttlDays)
This method is deprecated. Use hostCloudAnchorAsync(Anchor, int, BiConsumer) with ttlDays=1 instead.
boolean
isDepthModeSupported(Config.DepthMode mode)
Checks whether the provided Config.DepthMode is supported on this device with the selected camera configuration.
boolean
isGeospatialModeSupported(Config.GeospatialMode geospatialMode)
Checks whether the provided Config.GeospatialMode is supported on this device.
boolean
isImageStabilizationModeSupported(Config.ImageStabilizationMode imageStabilizationMode)
Checks whether the provided Config.ImageStabilizationMode is supported on this device with the selected camera configuration.
boolean
isSemanticModeSupported(Config.SemanticMode mode)
Checks whether the provided Config.SemanticMode is supported on this device with the selected camera configuration.
boolean
isSupported(Config config)
This method is deprecated. Please refer to (release notes 1.2.0).
void
pause()
Pause the current session.
Anchor
resolveCloudAnchor(String cloudAnchorId)
This method is deprecated. Use resolveCloudAnchorAsync(String, BiConsumer) instead.
ResolveCloudAnchorFuture
resolveCloudAnchorAsync(String cloudAnchorId, BiConsumer<AnchorAnchor.CloudAnchorState> callback)
Attempts to resolve a Cloud Anchor using the provided cloudAnchorId.
void
resume()
Starts or resumes the ARCore Session.
void
setCameraConfig(CameraConfig cameraConfig)
Sets the camera config to use.
void
setCameraTextureName(int textureId)
Sets the OpenGL texture name (id) that will allow GPU access to the camera image.
void
setCameraTextureNames(int[] textureIds)
Sets the OpenGL texture names (ids) that will be assigned to incoming camera frames in sequence in a ring buffer.
void
setDisplayGeometry(int displayRotation, int widthPx, int heightPx)
Sets the aspect ratio, coordinate scaling, and display rotation.
void
setPlaybackDataset(String mp4DatasetFilePath)
This method is deprecated. Please use setPlaybackDatasetUri(Uri) to play back datasets.
void
setPlaybackDatasetUri(Uri mp4DatasetUri)
Sets a MP4 dataset to play back instead of live camera feed.
void
startRecording(RecordingConfig recordingConfig)
Starts a new MP4 dataset file recording that is written to the specific filesystem path.
void
stopRecording()
Stops recording and flushes unwritten data to disk.
Frame
update()
Updates the state of the ARCore system.

Inherited Methods

Public Constructors

Public Methods