Android XR SDK พร้อมใช้งานในเวอร์ชันตัวอย่างสำหรับนักพัฒนาแอปแล้ว เราอยากฟังความคิดเห็นจากคุณ โปรดไปที่
หน้าการสนับสนุนเพื่อติดต่อเรา
ตรวจสอบความสามารถเชิงพื้นที่
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ความสามารถของพื้นที่ทำงานอาจเปลี่ยนแปลงไปเมื่อผู้ใช้โต้ตอบกับแอปหรือระบบ หรือแอปของคุณเองก็อาจเปลี่ยนแปลงความสามารถดังกล่าวได้ เช่น การเปลี่ยนเป็นโหมดพื้นที่ทำงานในบ้านหรือโหมดพื้นที่ทำงานแบบเต็ม แอปต้องตรวจสอบความสามารถเชิงพื้นที่เพื่อดูว่าระบบรองรับ API ใดบ้างในสภาพแวดล้อมปัจจุบัน เพื่อหลีกเลี่ยงปัญหา
ตรวจสอบความสามารถเชิงมิติพื้นที่โดยใช้ Jetpack Compose สำหรับ XR
Jetpack Compose สำหรับ XR จะสร้าง Composition Local เพื่อตรวจสอบความสามารถเชิงพื้นที่ ใช้เพื่อตรวจสอบว่าเปิดใช้ UI เชิงพื้นที่ เสียงรอบทิศทาง สภาพแวดล้อม การส่งผ่าน หรือเนื้อหา 3 มิติหรือไม่
คุณสามารถใช้ LocalSpatialCapabilities.current
เพื่อตรวจสอบว่าความสามารถเชิงพื้นที่ต่อไปนี้พร้อมใช้งานหรือไม่
ตัวอย่างต่อไปนี้แสดงวิธีตรวจสอบว่าเปิดใช้ UI แบบพื้นที่หรือไม่
if (LocalSpatialCapabilities.current.isSpatialUiEnabled) {
Subspace {
SpatialPanel(
modifier = SubspaceModifier
.width(1488.dp)
.fillMaxHeight()
) {
AppContent()
}
}
} else {
AppContent()
}
ตรวจสอบความสามารถเชิงพื้นที่โดยใช้ SceneCore
เมื่อใช้คลัง SceneCore คุณจะต้องสร้างเซสชัน เมื่อสร้างเซสชันแล้ว ให้เรียกใช้ spatialCapabilities
ในเซสชันเพื่อสอบถามความสามารถเชิงพื้นที่ที่พร้อมใช้งานในปัจจุบัน
นอกจากนี้ คุณยังเลือกสมัครรับการติดต่อกลับได้อีกด้วย ซึ่งจะaddSpatialCapabilitiesChangedListener
แจ้งให้คุณทราบเมื่อความสามารถของฟีเจอร์ดังกล่าวมีการเปลี่ยนแปลง
// Example 1: check if enabling passthrough mode is allowed
if (xrSession.scene.spatialCapabilities.hasCapability(
SpatialCapabilities.SPATIAL_CAPABILITY_PASSTHROUGH_CONTROL
)
) {
xrSession.scene.spatialEnvironment.preferredPassthroughOpacity = 1f
}
// Example 2: multiple capability flags can be checked simultaneously:
if (xrSession.scene.spatialCapabilities.hasCapability(
SpatialCapabilities.SPATIAL_CAPABILITY_PASSTHROUGH_CONTROL and
SpatialCapabilities.SPATIAL_CAPABILITY_3D_CONTENT
)
) {
// ...
}
ดูเพิ่มเติม
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-28 UTC
[[["เข้าใจง่าย","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-28 UTC"],[],[],null,["Spatial capabilities can change as users interact with your app or the system,\nor can even be changed by your app itself---for example, moving into Home Space or\nFull Space. To avoid issues, your app needs to check for spatial capabilities to\ndetermine which APIs are supported in the current environment.\n\nCheck for spatial capabilities using Jetpack Compose for XR\n\nJetpack Compose for XR creates a Composition Local for checking spatial\ncapabilities. Use this to check whether spatial UI, spatial audio, environments,\npassthrough, or 3D content is enabled.\n\nYou can use [`LocalSpatialCapabilities.current`](/reference/kotlin/androidx/xr/compose/platform/package-summary#LocalSpatialCapabilities()) to check if the following\nspatial capabilities are currently available:\n\n- [`isSpatialUiEnabled`](/reference/kotlin/androidx/xr/compose/platform/SpatialCapabilities#isSpatialUiEnabled()): Indicates whether the application may create spatial UI elements (for example, `SpatialPanel`).\n- [`isContent3dEnabled`](/reference/kotlin/androidx/xr/compose/platform/SpatialCapabilities#isContent3dEnabled()): Indicates whether the application may create 3D objects.\n- [`isAppEnvironmentEnabled`](/reference/kotlin/androidx/xr/compose/platform/SpatialCapabilities#isAppEnvironmentEnabled()): Indicates whether the application may set the environment.\n- [`isPassthroughControlEnabled`](/reference/kotlin/androidx/xr/compose/platform/SpatialCapabilities#isPassthroughControlEnabled()): Indicates whether the application may control the passthrough state.\n- [`isSpatialAudioEnabled`](/reference/kotlin/androidx/xr/compose/platform/SpatialCapabilities#isSpatialAudioEnabled()): Indicates whether the application may use spatial audio.\n\nThe following example shows how to check if spatial UI is enabled:\n\n\n```kotlin\nif (LocalSpatialCapabilities.current.isSpatialUiEnabled) {\n Subspace {\n SpatialPanel(\n modifier = SubspaceModifier\n .width(1488.dp)\n .fillMaxHeight()\n ) {\n AppContent()\n }\n }\n} else {\n AppContent()\n}https://github.com/android/snippets/blob/7a0ebbee11495f628cf9d574f6b6069c2867232a/xr/src/main/java/com/example/xr/compose/SpatialCapabilities.kt#L51-L63\n```\n\n\u003cbr /\u003e\n\nCheck for spatial capabilities using SceneCore\n\nWhen using the SceneCore library, you'll have to create a [session](/develop/xr/jetpack-xr-sdk/add-session). Once the\nsession is created, call [`spatialCapabilities`](/reference/kotlin/androidx/xr/scenecore/Scene#spatialCapabilities()) on the session to query\nwhich spatial capabilities are currently available.\n\n- [`SPATIAL_CAPABILITY_3D_CONTENT`](/reference/kotlin/androidx/xr/scenecore/SpatialCapabilities#SPATIAL_CAPABILITY_3D_CONTENT()): The activity can create 3D contents.\n- [`SPATIAL_CAPABILITY_APP_ENVIRONMENT`](/reference/kotlin/androidx/xr/scenecore/SpatialCapabilities#SPATIAL_CAPABILITY_APP_ENVIRONMENT()): The activity can set its own environment.\n- [`SPATIAL_CAPABILITY_EMBED_ACTIVITY`](/reference/kotlin/androidx/xr/scenecore/SpatialCapabilities#SPATIAL_CAPABILITY_EMBED_ACTIVITY()): The activity can spatially embed another activity.\n- [`SPATIAL_CAPABILITY_PASSTHROUGH_CONTROL`](/reference/kotlin/androidx/xr/scenecore/SpatialCapabilities#SPATIAL_CAPABILITY_PASSTHROUGH_CONTROL()): The activity can enable or disable passthrough.\n- [`SPATIAL_CAPABILITY_SPATIAL_AUDIO`](/reference/kotlin/androidx/xr/scenecore/SpatialCapabilities#SPATIAL_CAPABILITY_SPATIAL_AUDIO()): The activity can use spatial audio.\n- [`SPATIAL_CAPABILITY_UI`](/reference/kotlin/androidx/xr/scenecore/SpatialCapabilities#SPATIAL_CAPABILITY_UI()): The activity can spatialize itself (for example, adding a spatial panel).\n\nYou can also choose to subscribe to a callback,\n[`addSpatialCapabilitiesChangedListener`](/reference/kotlin/androidx/xr/scenecore/Scene#addSpatialCapabilitiesChangedListener(java.util.function.Consumer)) that notifies you when spatial\ncapabilities have changed.\n\n\n```kotlin\n// Example 1: check if enabling passthrough mode is allowed\nif (xrSession.scene.spatialCapabilities.hasCapability(\n SpatialCapabilities.SPATIAL_CAPABILITY_PASSTHROUGH_CONTROL\n )\n) {\n xrSession.scene.spatialEnvironment.preferredPassthroughOpacity = 1f\n}\n// Example 2: multiple capability flags can be checked simultaneously:\nif (xrSession.scene.spatialCapabilities.hasCapability(\n SpatialCapabilities.SPATIAL_CAPABILITY_PASSTHROUGH_CONTROL and\n SpatialCapabilities.SPATIAL_CAPABILITY_3D_CONTENT\n )\n) {\n // ...\n}https://github.com/android/snippets/blob/7a0ebbee11495f628cf9d574f6b6069c2867232a/xr/src/main/java/com/example/xr/scenecore/SpatialCapabilities.kt#L25-L39\n```\n\n\u003cbr /\u003e\n\nSee also\n\n- [Create a session](/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)"]]