開始建構沉浸式體驗

適用的 XR 裝置
本指南可協助您為這類 XR 裝置打造體驗。
XR 頭戴式裝置
有線 XR 眼鏡

安裝及設定 Android Studio、建立專案,並設定 Jetpack XR SDK 後,即可開始為 XR 頭戴式裝置和有線 XR 眼鏡等裝置打造沉浸式體驗。

開始探索各種建構方式之前,請先詳閱以下各節的資訊並完成所有工作,確保應用程式已設定為沉浸式 XR 開發。

設定應用程式的資訊清單檔案

與其他 Android 應用程式專案一樣,Android XR 應用程式必須有 AndroidManifest.xml 檔案,並包含特定資訊清單設定。資訊清單檔案會將應用程式的基本資訊,提供給 Android 建構工具、Android 作業系統和 Google Play。詳情請參閱應用程式資訊清單總覽指南。

如果是 XR 差異化應用程式,資訊清單檔案必須包含下列元素和屬性:

PROPERTY_XR_ACTIVITY_START_MODE 屬性

android:name="android.window.PROPERTY_XR_ACTIVITY_START_MODE" 屬性可讓系統知道,活動啟動時應以特定模式啟動。

這項屬性具有下列值:

  • XR_ACTIVITY_START_MODE_HOME_SPACE (僅限 Jetpack XR SDK)
  • XR_ACTIVITY_START_MODE_FULL_SPACE_MANAGED (僅限 Jetpack XR SDK)

XR_ACTIVITY_START_MODE_HOME_SPACE

使用這個啟動模式,在 Home Space 中啟動應用程式。在「主畫面」,多個應用程式可同時執行,因此使用者可以多工處理。任何行動裝置或大螢幕 Android 應用程式,以及使用 Jetpack XR SDK 建構的 XR 應用程式,都可以在首頁空間中運作。

<manifest ... >

   <application ... >
       <property
           android:name="android.window.PROPERTY_XR_ACTIVITY_START_MODE"
           android:value="XR_ACTIVITY_START_MODE_HOME_SPACE" />
       <activity
           android:name="com.example.myapp.MainActivity" ... >

           <intent-filter>
               <action android:name="android.intent.action.MAIN" />

               <category android:name="android.intent.category.LAUNCHER" />
           </intent-filter>
       </activity>
   </application>
</manifest>

XR_ACTIVITY_START_MODE_FULL_SPACE_MANAGED

使用這個啟動模式,在全螢幕中啟動應用程式。在全螢幕模式中,一次只能執行一個應用程式,沒有空間限制,其他應用程式都會隱藏。


<manifest ... >

   <application ... >
       <property
           android:name="android.window.PROPERTY_XR_ACTIVITY_START_MODE"
           android:value="XR_ACTIVITY_START_MODE_FULL_SPACE_MANAGED" />
       <activity
           android:name="com.example.myapp.MainActivity" ... >

           <intent-filter>
               <action android:name="android.intent.action.MAIN" />

               <category android:name="android.intent.category.LAUNCHER" />
           </intent-filter>
       </activity>
   </application>
</manifest>

android:name="android.window.PROPERTY_XR_BOUNDARY_TYPE_RECOMMENDED" 屬性表示應用程式應以特定類型的邊界啟動。如果應用程式設計目的是讓使用者在實體空間中移動,則必須指定 XR_BOUNDARY_TYPE_LARGE。指定 XR_BOUNDARY_TYPE_NO_RECOMMENDATION 時,系統不會提供安全邊界類型的建議,而是使用目前使用的類型。

<manifest ... >

   <application ... >
       <property
           android:name="android.window.PROPERTY_XR_BOUNDARY_TYPE_RECOMMENDED"
           android:value="XR_BOUNDARY_TYPE_LARGE" />
   </application>
</manifest>

XR 應用程式的 PackageManager 功能

透過 Google Play 商店發行應用程式時,您可以在應用程式資訊清單中指定必要的硬體或軟體功能。uses-feature 元素可讓 Play 商店適當篩選向使用者顯示的應用程式。

下列功能僅適用於 XR 差異化應用程式。

android.software.xr.api.spatial

使用 Jetpack XR SDK 建構的應用程式,必須在應用程式資訊清單中加入這項功能。android:required 屬性的設定值取決於應用程式的發布群組。

如果應用程式將 XR 差異化功能或內容,整合至現有的行動裝置 APK,並發布至行動裝置發布群組,請將 android:required 屬性設為 false:

<!-- If you are publishing an existing mobile APK using the mobile release track, set android:required to false.-->
<uses-feature android:name="android.software.xr.api.spatial" android:required="false" />

如果應用程式是專為支援 XR 的裝置建構,並發布至 Android XR 專用發布群組,請將 android:required 屬性設為 true:

<!-- If you are publishing a separate APK for XR using the dedicated Android XR release track, set android:required to true.-->
<uses-feature android:name="android.software.xr.api.spatial" android:required="true" />

android.hardware.xr.input.controller

這項功能表示應用程式需要高精確度的 6DoF (自由度) 動作控制器輸入,才能正常運作。如果應用程式支援控制器,且沒有控制器就無法運作,請將值設為 true。如果應用程式支援控制器,但沒有控制器也能運作,請設為 false。

<!-- Sets android:required to true, indicating that your app can't function on devices without controllers. -->
<uses-feature android:name="android.hardware.xr.input.controller" android:required="true" />

android.hardware.xr.input.hand_tracking

這個旗標表示應用程式需要高擬真手勢追蹤功能,才能正常運作,包括使用者手部關節的位置、方向和速度。如果應用程式支援手勢追蹤,且必須有這項功能才能運作,請將值設為 true。如果應用程式支援手勢追蹤,但沒有這項功能也能運作,請設為 false。

<!-- Sets android:required to true, indicating that your app can't function on devices without hand tracking. -->
<uses-feature android:name="android.hardware.xr.input.hand_tracking" android:required="true" />

android.hardware.xr.input.eye_tracking

這個旗標表示應用程式需要高擬真度眼動追蹤,才能正確輸入。如果應用程式支援眼動追蹤輸入功能,且必須啟用這項功能才能運作,請將值設為 true。如果應用程式支援眼動追蹤輸入,但沒有這項功能也能運作,請設為 false。

<!-- Sets android:required to true, indicating that your app can't function on devices without eye tracking. -->
<uses-feature android:name="android.hardware.xr.input.eye_tracking" android:required="true" />

android.hardware.xr.input.face_tracking

這個旗標表示應用程式需要臉部追蹤硬體才能正常運作。如果應用程式支援臉部追蹤功能,且沒有這項功能就無法運作,請將值設為 true。如果應用程式支援臉部追蹤,但沒有這項功能也能運作,請將其設為 false。

<!-- Sets android:required to true, indicating that your app can't function on devices without face tracking. -->
<uses-feature android:name="android.hardware.xr.input.face_tracking" android:required="true" />

行動裝置和大螢幕應用程式的應用程式資訊清單相容性考量

如「XR 應用程式的 PackageManager 功能」一節所述,應用程式會在應用程式資訊清單的 <uses-feature> 元素中宣告使用的功能。部分功能 (例如電話或 GPS) 可能不適用於所有裝置。

如要取得裝置啟用的功能清單,請執行 adb shell pm list features。

不支援的功能

Google Play 商店會篩選可在裝置上安裝的應用程式,篩選依據是下列 Android 功能宣告。

相機硬體

android.hardware.camera.ar

android.hardware.camera.autofocus

android.hardware.camera.capability.manual_post_processing

android.hardware.camera.capability.manual_sensor

android.hardware.camera.capability.raw

android.hardware.camera.concurrent

android.hardware.camera.external

android.hardware.camera.flash

android.hardware.camera.level.full

連線能力

android.hardware.ethernet

android.hardware.uwb

android.hardware.ipsec_tunnel_migration

裝置設定

android.hardware.ram.low

板型規格設定

android.hardware.type.automotive

android.hardware.type.embedded

android.hardware.type.pc

android.hardware.type.television

android.hardware.type.watch

android.software.leanback

android.software.leanback_only

android.software.live_tv

輸入

android.hardware.consumerir

android.software.input_methods

位置

android.hardware.location.gps

近距離無線通訊

android.hardware.nfc

android.hardware.nfc.ese

android.hardware.nfc.hce

android.hardware.nfc.hcef

android.hardware.nfc.uicc

android.hardware.nfc.beam

安全性設定和硬體

android.hardware.se.omapi.ese

android.hardware.se.omapi.sd

android.hardware.se.omapi.uicc

android.hardware.biometrics.face

android.hardware.fingerprint

android.hardware.identity_credential

android.hardware.identity_credential_direct_access

android.hardware.keystore.limited_use_key

android.hardware.keystore.single_use_key

android.hardware.strongbox_keystore

感應器

android.hardware.sensor.accelerometer_limited_axes

android.hardware.sensor.accelerometer_limited_axes_uncalibrated

android.hardware.sensor.ambient_temperature

android.hardware.sensor.barometer

android.hardware.sensor.gyroscope_limited_axes

android.hardware.sensor.gyroscope_limited_axes_uncalibrated

android.hardware.sensor.heading

android.hardware.sensor.heartrate

android.hardware.sensor.heartrate.ecg

android.hardware.sensor.hinge_angle

android.hardware.sensor.light

android.hardware.sensor.relative_humidity

android.hardware.sensor.stepcounter

android.hardware.sensor.stepdetector

軟體設定

android.software.backup

android.software.connectionservice

android.software.expanded_picture_in_picture

android.software.live_wallpaper

android.software.picture_in_picture

android.software.telecom

android.software.wallet_location_based_suggestions

電話通訊系統

android.hardware.telephony

android.hardware.telephony.calling

android.hardware.telephony.cdma

android.hardware.telephony.data

android.hardware.telephony.euicc

android.hardware.telephony.euicc.mep

android.hardware.telephony.gsm

android.hardware.telephony.ims

android.hardware.telephony.mbms

android.hardware.telephony.messaging

android.hardware.telephony.radio.access

android.hardware.telephony.subscription

android.software.sip

android.software.sip.voip

虛擬實境 (舊版)

android.hardware.vr.headtracking

android.hardware.vr.high_performance

android.software.vr.mode

小工具

android.software.app_widgets

後續步驟

現在您已完成應用程式資訊清單設定,並查看重要資訊,接下來請探索如何打造沉浸式體驗: