ARCore-Sitzung unter Android konfigurieren
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Konfiguriere eine ARCore-Sitzung, um AR-Funktionen für deine App zu entwickeln.
Was ist eine Sitzung?
Alle AR-Prozesse wie Bewegungserkennung,
Umgebungsverständnis und die Schätzung der Beleuchtung
werden in einem ARCore-Modell durchgeführt,
Sitzung. Session
ist der Haupteinstiegspunkt für ARCore
der API erstellen. Es verwaltet den AR-Systemstatus und den Sitzungslebenszyklus.
die App, um eine Sitzung zu erstellen, zu konfigurieren, zu starten oder zu beenden. Am wichtigsten ist,
ermöglicht es der App, Frames zu empfangen, die Zugriff auf das Kamerabild und
Position des Geräts.
Die Sitzung kann verwendet werden, um die folgenden Funktionen zu konfigurieren:
Prüfen, ob ARCore installiert und auf dem neuesten Stand ist
Bevor Sie ein Session
erstellen, prüfen Sie, ob ARCore installiert und auf dem neuesten Stand ist. Wenn
ARCore ist nicht installiert, die Sitzungserstellung schlägt fehl und jede weitere Installation schlägt fehl
oder ein ARCore-Upgrade erfordert einen Neustart der App.
Java
// Verify that ARCore is installed and using the current version.
private boolean isARCoreSupportedAndUpToDate() {
ArCoreApk.Availability availability = ArCoreApk.getInstance().checkAvailability(this);
switch (availability) {
case SUPPORTED_INSTALLED:
return true;
case SUPPORTED_APK_TOO_OLD:
case SUPPORTED_NOT_INSTALLED:
try {
// Request ARCore installation or update if needed.
ArCoreApk.InstallStatus installStatus = ArCoreApk.getInstance().requestInstall(this, true);
switch (installStatus) {
case INSTALL_REQUESTED:
Log.i(TAG, "ARCore installation requested.");
return false;
case INSTALLED:
return true;
}
} catch (UnavailableException e) {
Log.e(TAG, "ARCore not installed", e);
}
return false;
case UNSUPPORTED_DEVICE_NOT_CAPABLE:
// This device is not supported for AR.
return false;
case UNKNOWN_CHECKING:
// ARCore is checking the availability with a remote query.
// This function should be called again after waiting 200 ms to determine the query result.
case UNKNOWN_ERROR:
case UNKNOWN_TIMED_OUT:
// There was an error checking for AR availability. This may be due to the device being offline.
// Handle the error appropriately.
}
}
Kotlin
// Verify that ARCore is installed and using the current version.
fun isARCoreSupportedAndUpToDate(): Boolean {
return when (ArCoreApk.getInstance().checkAvailability(this)) {
Availability.SUPPORTED_INSTALLED -> true
Availability.SUPPORTED_APK_TOO_OLD, Availability.SUPPORTED_NOT_INSTALLED -> {
try {
// Request ARCore installation or update if needed.
when (ArCoreApk.getInstance().requestInstall(this, true)) {
InstallStatus.INSTALL_REQUESTED -> {
Log.i(TAG, "ARCore installation requested.")
false
}
InstallStatus.INSTALLED -> true
}
} catch (e: UnavailableException) {
Log.e(TAG, "ARCore not installed", e)
false
}
}
Availability.UNSUPPORTED_DEVICE_NOT_CAPABLE ->
// This device is not supported for AR.
false
Availability.UNKNOWN_CHECKING -> {
// ARCore is checking the availability with a remote query.
// This function should be called again after waiting 200 ms to determine the query result.
}
Availability.UNKNOWN_ERROR, Availability.UNKNOWN_TIMED_OUT -> {
// There was an error checking for AR availability. This may be due to the device being offline.
// Handle the error appropriately.
}
}
}
Sitzung erstellen
Eine Sitzung in ARCore erstellen und konfigurieren
Java
public void createSession() {
// Create a new ARCore session.
session = new Session(this);
// Create a session config.
Config config = new Config(session);
// Do feature-specific operations here, such as enabling depth or turning on
// support for Augmented Faces.
// Configure the session.
session.configure(config);
}
Kotlin
fun createSession() {
// Create a new ARCore session.
session = Session(this)
// Create a session config.
val config = Config(session)
// Do feature-specific operations here, such as enabling depth or turning on
// support for Augmented Faces.
// Configure the session.
session.configure(config)
}
Sitzung schließen
Session
besitzt eine erhebliche Menge an nativem Heap-Speicher. Wenn Sie nicht explizit
Wenn du die Sitzung schließt, kann es sein, dass der native Arbeitsspeicher nicht mehr ausreicht und deine App abstürzt. Wann?
die AR-Sitzung nicht mehr benötigt wird, rufen Sie
close()
zum Release
Ressourcen. Wenn deine App eine einzelne AR-fähige Aktivität enthält, rufe close()
auf
aus der onDestroy()
-Methode der Aktivität.
Java
// Release native heap memory used by an ARCore session.
session.close();
Kotlin
// Release native heap memory used by an ARCore session.
session.close()
Nächste Schritte
Sofern nicht anders angegeben, sind die Inhalte dieser Seite unter der Creative Commons Attribution 4.0 License und Codebeispiele unter der Apache 2.0 License lizenziert. Weitere Informationen finden Sie in den Websiterichtlinien von Google Developers. Java ist eine eingetragene Marke von Oracle und/oder seinen Partnern.
Zuletzt aktualisiert: 2025-07-26 (UTC).
[null,null,["Zuletzt aktualisiert: 2025-07-26 (UTC)."],[[["\u003cp\u003eARCore sessions manage all AR processes like motion tracking and environmental understanding, and are accessed via the \u003ccode\u003eSession\u003c/code\u003e object.\u003c/p\u003e\n"],["\u003cp\u003eBefore creating an ARCore session, ensure ARCore is installed and up-to-date on the device to prevent session creation failures.\u003c/p\u003e\n"],["\u003cp\u003eTo configure features like lighting estimation or cloud anchors, utilize the \u003ccode\u003eConfig\u003c/code\u003e object and apply it to the session.\u003c/p\u003e\n"],["\u003cp\u003eTo prevent memory leaks and crashes, explicitly close the session using \u003ccode\u003esession.close()\u003c/code\u003e when it's no longer needed, such as in the activity's \u003ccode\u003eonDestroy()\u003c/code\u003e method.\u003c/p\u003e\n"]]],[],null,["# Configure an ARCore session in Android\n\nConfigure an ARCore session to build AR experiences for your app.\n\nWhat is a session?\n------------------\n\nAll [AR processes](/ar/discover/concepts), such as motion tracking,\nenvironmental understanding, and lighting estimation, happen inside an ARCore\nsession. [`Session`](/ar/reference/java/com/google/ar/core/Session) is the main entry point to the ARCore\nAPI. It manages the AR system state and handles the session lifecycle, allowing\nthe app to create, configure, start, or stop a session. Most importantly, it\nenables the app to receive frames that allow access to the camera image and\ndevice pose.\n\nThe session can be used to configure the following features:\n\n- [Lighting Estimation](/ar/develop/lighting-estimation)\n- [Cloud Anchors](/ar/develop/cloud-anchors)\n- [Augmented Images](/ar/develop/augmented-images)\n- [Augmented Faces](/ar/develop/augmented-faces)\n- [Depth API](/ar/develop/depth)\n- [Instant Placement](/ar/develop/instant-placement)\n- [ARCore Geospatial API](/ar/develop/geospatial)\n\nVerify that ARCore is installed and up to date\n----------------------------------------------\n\nBefore creating a `Session`, verify that ARCore is installed and up to date. If\nARCore isn't installed, session creation fails and any subsequent installation\nor upgrade of ARCore requires an app restart. \n\n### Java\n\n // Verify that ARCore is installed and using the current version.\n private boolean isARCoreSupportedAndUpToDate() {\n ArCoreApk.Availability availability = ArCoreApk.getInstance().checkAvailability(this);\n switch (availability) {\n case SUPPORTED_INSTALLED:\n return true;\n\n case SUPPORTED_APK_TOO_OLD:\n case SUPPORTED_NOT_INSTALLED:\n try {\n // Request ARCore installation or update if needed.\n ArCoreApk.InstallStatus installStatus = ArCoreApk.getInstance().requestInstall(this, true);\n switch (installStatus) {\n case INSTALL_REQUESTED:\n Log.i(TAG, \"ARCore installation requested.\");\n return false;\n case INSTALLED:\n return true;\n }\n } catch (UnavailableException e) {\n Log.e(TAG, \"ARCore not installed\", e);\n }\n return false;\n\n case UNSUPPORTED_DEVICE_NOT_CAPABLE:\n // This device is not supported for AR.\n return false;\n\n case UNKNOWN_CHECKING:\n // ARCore is checking the availability with a remote query.\n // This function should be called again after waiting 200 ms to determine the query result.\n case UNKNOWN_ERROR:\n case UNKNOWN_TIMED_OUT:\n // There was an error checking for AR availability. This may be due to the device being offline.\n // Handle the error appropriately.\n }\n }\n\n### Kotlin\n\n // Verify that ARCore is installed and using the current version.\n fun isARCoreSupportedAndUpToDate(): Boolean {\n return when (ArCoreApk.getInstance().checkAvailability(this)) {\n Availability.SUPPORTED_INSTALLED -\u003e true\n Availability.SUPPORTED_APK_TOO_OLD, Availability.SUPPORTED_NOT_INSTALLED -\u003e {\n try {\n // Request ARCore installation or update if needed.\n when (ArCoreApk.getInstance().requestInstall(this, true)) {\n InstallStatus.INSTALL_REQUESTED -\u003e {\n Log.i(TAG, \"ARCore installation requested.\")\n false\n }\n InstallStatus.INSTALLED -\u003e true\n }\n } catch (e: UnavailableException) {\n Log.e(TAG, \"ARCore not installed\", e)\n false\n }\n }\n\n Availability.UNSUPPORTED_DEVICE_NOT_CAPABLE -\u003e\n // This device is not supported for AR.\n false\n\n Availability.UNKNOWN_CHECKING -\u003e {\n // ARCore is checking the availability with a remote query.\n // This function should be called again after waiting 200 ms to determine the query result.\n }\n Availability.UNKNOWN_ERROR, Availability.UNKNOWN_TIMED_OUT -\u003e {\n // There was an error checking for AR availability. This may be due to the device being offline.\n // Handle the error appropriately.\n }\n }\n }\n\nCreate a session\n----------------\n\nCreate and configure a session in ARCore. \n\n### Java\n\n public void createSession() {\n // Create a new ARCore session.\n session = new Session(this);\n\n // Create a session config.\n Config config = new Config(session);\n\n // Do feature-specific operations here, such as enabling depth or turning on\n // support for Augmented Faces.\n\n // Configure the session.\n session.configure(config);\n }\n\n### Kotlin\n\n fun createSession() {\n // Create a new ARCore session.\n session = Session(this)\n\n // Create a session config.\n val config = Config(session)\n\n // Do feature-specific operations here, such as enabling depth or turning on\n // support for Augmented Faces.\n\n // Configure the session.\n session.configure(config)\n }\n\nClose a session\n---------------\n\n`Session` owns a significant amount of native heap memory. Failure to explicitly\nclose the session may cause your app to run out of native memory and crash. When\nthe AR session is no longer needed, call\n[`close()`](/ar/reference/java/com/google/ar/core/Session#close()) to release\nresources. If your app contains a single AR-enabled activity, call `close()`\nfrom the activity's `onDestroy()` method. \n\n### Java\n\n // Release native heap memory used by an ARCore session.\n session.close();\n\n### Kotlin\n\n // Release native heap memory used by an ARCore session.\n session.close()\n\nNext steps\n----------\n\n- [ARCore quickstart for Android](/ar/develop/java/quickstart)"]]