開始建構沉浸式體驗

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

安裝及設定 Android Studio建立專案,並設定 Jetpack XR SDK 後,即可開始建構沉浸式體驗。

開始探索各種建構方式前,請先詳閱下列各節的資訊,並完成所有工作,確保應用程式已設定為沉浸式 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

使用這個啟動模式,在首頁空間中啟動應用程式。在主畫面模式中,多個應用程式可同時執行,因此使用者可以多工處理。任何行動裝置或大螢幕 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 商店發布應用程式時,您可以在應用程式資訊清單中指定必要的硬體或軟體功能。Play 商店會根據 uses-feature 元素,適當篩選向使用者顯示的應用程式。

下列功能是 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" />

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

如「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

後續步驟

您已完成應用程式資訊清單的設定,並檢查過重要資訊,現在可以探索如何建構沉浸式體驗: