Class ARSession
- All Implemented Interfaces:
AutoCloseable
Active augmented reality session. Obtained from
AR#open(ARSessionOptions).
Only one ARSession may be open at a time; opening a second throws
IllegalStateException. Closing the session releases the camera and
tracking hardware and invalidates the ARView returned by
#createView().
All events are delivered on the EDT and every getter reflects the state as of the most recently delivered events. High-frequency refinements (anchor and plane updates, camera pose, light estimate) are coalesced so the EDT sees the latest value rather than a backlog.
-
Method Summary
Modifier and TypeMethodDescriptionvoidRegisters an anchor listener.voidRegisters a plane listener.voidRegisters a tracking state listener.voidclose()Releases the session.createAnchor(ARPose pose) Creates an anchor at an arbitrary world pose and registers it with the session.Creates the AR view that renders the camera image composited with the anchored content.ARAnchor[]The anchors currently registered with the session, in registration order.The latest device pose in world space.The latest estimate of real-world lighting.The options the session was opened with.ARPlane[]The planes the session currently tracks, in detection order.Why tracking is degraded, orARTrackingFailureReason#NONEwhen it is not.The session's overall tracking quality as of the latest update.hitTest(float xNorm, float yNorm) Performs an asynchronous hit test from a normalized view coordinate (0.0top left to1.0bottom right) into the world.booleanisClosed()True once#close()has been called on this session.voidpause()Suspends tracking and the camera while keeping this session object alive.voidRemoves an anchor listener.voidRemoves a plane listener.voidRemoves a tracking state listener.voidresume()Re-acquires the camera and resumes tracking after#pause().
-
Method Details
-
createView
Creates the AR view that renders the camera image composited with the anchored content. Each session owns one view; subsequent calls return the same instance. -
getOptions
The options the session was opened with. Read-only snapshot; mutating it afterAR#open(ARSessionOptions)has no effect. -
getTrackingState
The session's overall tracking quality as of the latest update. -
getTrackingFailureReason
Why tracking is degraded, orARTrackingFailureReason#NONEwhen it is not. -
getCameraPose
The latest device pose in world space. Poll-style: the value refreshes every frame without firing events. -
getLightEstimate
The latest estimate of real-world lighting. Poll-style: the value refreshes every frame without firing events. Before the first platform estimate this returnsARLightEstimate#INVALID. -
hitTest
Performs an asynchronous hit test from a normalized view coordinate (
0.0top left to1.0bottom right) into the world. The returnedAsyncResourceresolves on the EDT with the intersections ordered nearest first; an empty array means nothing was hit.Parameters
-
xNorm: the horizontal view coordinate,0.0to1.0 -
yNorm: the vertical view coordinate,0.0to1.0
Returns
resolves with the hits; call
ARHitResult#createAnchor()on one to place content there -
-
createAnchor
-
getAnchors
The anchors currently registered with the session, in registration order. -
getPlanes
The planes the session currently tracks, in detection order. -
addTrackingListener
Registers a tracking state listener. Events fire on the EDT. -
removeTrackingListener
Removes a tracking state listener. -
addPlaneListener
Registers a plane listener. Events fire on the EDT. -
removePlaneListener
Removes a plane listener. -
addAnchorListener
Registers an anchor listener. Events fire on the EDT. -
removeAnchorListener
Removes an anchor listener. -
pause
public void pause()Suspends tracking and the camera while keeping this session object alive. Pair with#resume(). -
resume
public void resume()Re-acquires the camera and resumes tracking after#pause(). -
close
public void close()Releases the session. Idempotent.- Specified by:
closein interfaceAutoCloseable
-
isClosed
public boolean isClosed()True once#close()has been called on this session.
-