Manages AR system state and handles the session lifecycle. This class is the main entry point to ARCore API. This class allows the user to create a session, configure it, start/stop it, and most importantly receive frames that allow access to camera image and device pose.
(FOR TESTING) Constructs a new instance for use as a mock.
Returns all known anchors, including those not currently tracked.
|<T extends Trackable> Collection<T>|
Gets the current config.
Pause the current session.
Starts or resumes the ARCore Session.
Sets the OpenGL texture name (id) that will allow GPU access to the camera image.
setDisplayGeometry(int displayRotation, int widthPx, int heightPx)
Sets the aspect ratio, coordinate scaling, and display rotation.
Updates the state of the ARCore system.
public Session (Context context)
Creates a new ARCore session. This must be the first ARCore action that your application takes.
|FatalException||if an internal error occurred while
creating the session.
|UnavailableArcoreNotInstalledException||if the ARCore APK is not present|
|UnavailableSdkTooOldException||if the ARCore SDK that this application was built with is too old and no longer supported by the installed ARCore APK.|
|UnavailableApkTooOldException||if the installed ARCore APK is too old for the ARCore SDK with which this application was built.|
|SecurityException||if client app fails to grant CameraPermission.|
|FatalException||if initialization failed for any other reason.|
protected Session ()
(FOR TESTING) Constructs a new instance for use as a mock. Calling any base method implementation on this instance may return unexpected results, throw an exception, or even crash.
To create a
Session normally, use
public void configure (Config config)
Configures the session.
A session initially has a default configuration. This should be called if a configuration different than default is needed.
|config||The new configuration setting for the session.|
|UnsupportedConfigurationException||if the configuration requested is not supported.|
public Collection<Anchor> getAllAnchors ()
public Collection<T> getAllTrackables (Class<T> filterType)
public void getConfig (Config configToFill)
public Config getConfig ()
Uses the pose and other data from
anchor to create a new anchor that will be hosted.
anchor will have the cloud anchor state
|anchor||The anchor whose pose is to be hosted.|
- The new anchor with the same pose as
anchorwhich will be hosted.
public boolean isSupported (Config config)
This method was deprecated
in API level .
in release 1.2.0. Please refer to (release notes 1.2.0).
Before release 1.2.0: Checks if the provided configuration is usable on the this device. If
this method returns false, calls to
configure(Config) with this configuration will
throw an exception.
This function now always returns true. See documentation for each configuration entry to know which configuration options & combinations are supported.
|config||the configuration to test|
public void pause ()
Pause the current session. This method will stop the camera feed and release resources. The
session can be restarted again by calling
Typically this should be called from
Note that ARCore might continue consuming substantial computing resources for up to 10 seconds after calling this method.
Creates a new anchor whose pose will be resolved from the ARCore Cloud using the given
cloudAnchorId. The returned
anchor will have the cloud anchor state
|cloudAnchorId||The cloud anchor ID of the cloud anchor.|
- The new anchor whose pose will be resolved in a later call to
public void resume ()
public void setCameraTextureName (int textureId)
Sets the OpenGL texture name (id) that will allow GPU access to the camera image. The provided
ID should have been created with
glGenTextures(int, int, int). The resulting
texture must be bound to the
GL_TEXTURE_EXTERNAL_OES target for use. Shaders
accessing this texture must use a
samplerExternalOES sampler. See sample code for an
|textureId||a valid OpenGL texture name (id)|
public void setDisplayGeometry (int displayRotation, int widthPx, int heightPx)
Sets the aspect ratio, coordinate scaling, and display rotation. This data is used by UV conversion, projection matrix generation, and hit test logic.
public Frame update ()
Updates the state of the ARCore system. This includes: receiving a new camera frame, updating the location of the device, updating the location of tracking anchors, updating detected planes, etc.
This call may cause off-screen OpenGL activity. Because of this, to avoid unnecessary frame buffer flushes and reloads, this call should not be made in the middle of rendering a frame or offscreen buffer.
This call may update the pose of all created anchors and detected planes. The set of updated
objects is accessible through
This call in blocking mode (see
Config.UpdateMode) will wait until a new camera
image is available, or until the built-in timeout (currently 66ms) is reached. If the camera
image does not arrive by the built-in timeout, then update() will return the most recent
Frame object. For some applications it may be important to know if a new frame was actually
obtained (for example, to avoid redrawing if the camera did not produce a new frame). To do
that, compare the current frame's timestamp, obtained via
the previously recorded frame timestamp. If they are different, this is a new frame.
- The most recent Frame received