تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
يقدّم Session الواجهة الأساسية للوظائف المتعلّقة بالموقع الجغرافي
للتطبيق. يجب أن ينشئ كل نشاط مُحدَّد بموقع جغرافي مثيلًا
من Session ويحتفظ به. بعد إنشاء التطبيق، يمكنه استخدام واجهات Session ل
إنشاء عناصر محتوى مكاني مثل اللوحات أو النماذج الثلاثية الأبعاد، بالإضافة إلى ضبط
بيئة مكانية وتحديد موضع المستخدم وتثبيت المحتوى
في العالم الواقعي.
الوصول إلى جلسة من Jetpack Compose لأجهزة الواقع المعزّز
عند استخدام Jetpack Compose لتجربة الواقع المعزّز، يتم إنشاء الجلسة نيابةً عنك ويمكن
الوصول إليها باستخدام LocalSession.current. راجِع المثال التالي:
إذا كنت تنشئ عناصر ثلاثية الأبعاد من مكتبة SceneCore، عليك
إنشاء الجلسة.
لا يمكن إنشاء جلسة إلا على جهاز Android XR. سيؤدي محاولة
إنشاء جلسة على جهاز غير متوافق إلى تعذُّر إكمال العملية. ل
إنشاء جلسة، عليك تمرير نشاط إلى طريقة create()، كما هو موضّح في
المثال التالي.
when(valresult=Session.create(this)){isSessionCreateSuccess->{valxrSession=result.session// ...}else->
TODO(/* A different unhandled exception was thrown. */)}
يخضع كل من المحتوى وعيّنات التعليمات البرمجية في هذه الصفحة للتراخيص الموضحّة في ترخيص استخدام المحتوى. إنّ Java وOpenJDK هما علامتان تجاريتان مسجَّلتان لشركة Oracle و/أو الشركات التابعة لها.
تاريخ التعديل الأخير: 2025-08-23 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","easyToUnderstand","thumb-up"],["ساعَدني المحتوى في حلّ مشكلتي.","solvedMyProblem","thumb-up"],["غير ذلك","otherUp","thumb-up"]],[["لا يحتوي على المعلومات التي أحتاج إليها.","missingTheInformationINeed","thumb-down"],["الخطوات معقدة للغاية / كثيرة جدًا.","tooComplicatedTooManySteps","thumb-down"],["المحتوى قديم.","outOfDate","thumb-down"],["ثمة مشكلة في الترجمة.","translationIssue","thumb-down"],["مشكلة في العيّنات / التعليمات البرمجية","samplesCodeIssue","thumb-down"],["غير ذلك","otherDown","thumb-down"]],["تاريخ التعديل الأخير: 2025-08-23 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],null,["# Session\n\nThe [`Session`](/reference/kotlin/androidx/xr/runtime/Session) provides the primary interface to spatialized functionality\nfor the application. Each spatialized Activity must create and hold an instance\nof `Session`. Once created, the application can use the `Session` interfaces to\ncreate spatialized content entities such as panels or 3d models, as well as [set\na spatial environment](/develop/xr/jetpack-xr-sdk/add-environments), [identify user position](/reference/kotlin/androidx/xr/scenecore/SpatialUser), and [anchor content](/develop/xr/jetpack-xr-sdk/work-with-entities)\nto the real world.\n| **Caution:** Due to a [known issue](/jetpack/androidx/releases/xr-scenecore#1.0.0-alpha04) that ties the session to the Activity lifecycle, the session can become invalid in various situations that automatically recreate the activity. These include, but are not limited to resizing a main panel, connecting peripherals, and changing between light and dark theme. If you run into session invalidation issues, you may need to make your main panel non-resizable, use a dynamic panel entity, disable activity recreation for [specific config changes](/guide/topics/resources/runtime-changes#restrict-activity), or disable light or dark theme changes.\n\nAccess Session from Jetpack Compose for XR\n------------------------------------------\n\nWhen using Jetpack Compose for XR, the session is created for you and can be\naccessed using [`LocalSession.current`](/reference/kotlin/androidx/xr/compose/platform/package-summary#LocalSession()). See the following example:\n\n\n```kotlin\n@Composable\nfun ComposableUsingSession() {\n val session = LocalSession.current\n}https://github.com/android/snippets/blob/dd30aee903e8c247786c064faab1a9ca8d10b46e/xr/src/main/java/com/example/xr/runtime/Session.kt#L26-L29\n```\n\n\u003cbr /\u003e\n\nAccess Session from Jetpack SceneCore\n-------------------------------------\n\nIf you are creating spatialized entities from the SceneCore library, you'll need\nto create the session.\n\nCreating a session is only supported on an Android XR device. Attempting to\ncreate a session on an incompatible device will result in a failed result. To\ncreate a session, pass an activity to the [`create()`](/reference/kotlin/androidx/xr/runtime/Session#create(android.app.Activity,kotlin.coroutines.CoroutineContext)) method, as shown in\nthe following example.\n\n\n```kotlin\nwhen (val result = Session.create(this)) {\n is SessionCreateSuccess -\u003e {\n val xrSession = result.session\n // ...\n }\n else -\u003e\n TODO(/* A different unhandled exception was thrown. */)\n}https://github.com/android/snippets/blob/dd30aee903e8c247786c064faab1a9ca8d10b46e/xr/src/main/java/com/example/xr/runtime/Session.kt#L34-L41\n```\n\n\u003cbr /\u003e\n\n| **Note:** Some features, such as [hand tracking](/develop/xr/jetpack-xr-sdk/arcore/hands) and [plane tracking](/develop/xr/jetpack-xr-sdk/arcore/planes), require additional runtime permissions in order for session configuration to succeed.\n\nWhen a session's activity is destroyed, all spatial UI and 3D content associated\nwith that session is destroyed and the session is no longer valid.\n\nSee also\n--------\n\n- [Check for spatial capabilities](/develop/xr/jetpack-xr-sdk/check-spatial-capabilities)\n- [Transition between HSM and FSM](/develop/xr/jetpack-xr-sdk/transition-home-space-to-full-space)\n- [Add spatial environments to your app](/develop/xr/jetpack-xr-sdk/add-environments)\n- [Add 3D models to your app](/develop/xr/jetpack-xr-sdk/add-3d-models)"]]