為協助您建構可與 Matter 裝置互動的 Android 應用程式,Google 開發了 Google Home Mobile SDK。Mobile SDK 包含兩項核心 API,可讓應用程式委派裝置並與 Google 網狀架構共用裝置。
裝置加入 Google 網狀架構後,使用者就能透過 Google Home app (GHA)、Android 電源控制選項、語音和 Nest 觸控螢幕裝置控制裝置。
Mobile SDK 也可讓您定義自訂委派服務,用來將裝置委派給其他 Matter 生態系統。
將 Mobile SDK 整合到 Android 應用程式中
如要開始使用,請完成下列步驟:
按照「設定 Google Play services」中的指示操作。
將 Play services 依附元件新增至
build.gradle
檔案:implementation 'com.google.android.gms:play-services-home:16.0.0-beta1'
確保模組傳送成功
Play services home
模組為選用模組,因此只有在裝置上的應用程式於 AndroidManifest.xml
檔案中指定適當的 Play services 模組依附元件時,使用者裝置上才會出現 Matter 功能。
GHA 和 Google Home Sample App for Matter 兩者都會在資訊清單中加入這個模組依附元件。如果您要將 Mobile SDK 整合至 Android 應用程式,請在 AndroidManifest.xml
檔案的 application
宣告中新增下列 service
區塊,確保為應用程式使用者提供 Matter 支援:
<service android:name="com.google.android.gms.metadata.ModuleDependencies"
android:enabled="false"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.metadata.MODULE_DEPENDENCIES" />
</intent-filter>
<meta-data android:name="home:0:preferred" android:value=""/>
</service>
這項功能僅適用於搭載 Android 22.50.14 以上版本的裝置。Play services
如需實作範例,請參閱 Sample App for Matter的資訊清單。
您可以使用 ModuleInstallClient
在執行階段檢查 Home 模組是否可用。詳情請參閱「使用 ModuleInstallClient 確保 API 可用性」頁面。
呼叫其他 Android 應用程式
如果您使用 Android 11 以上版本,請在 AndroidManifest.xml
中加入下列 queries
區塊,讓應用程式能呼叫其他應用程式。
<queries>
<!-- For GMS Core/Play service -->
<package android:name="com.google.android.gms" />
<package android:name="com.android.vending" />
<!-- End of GMS Core/Play service-->
</queries>
詳情請參閱「在 Android 上篩選套件瀏覽權限」一文。
使用 Google Home Sample App for Matter
如要瞭解如何從 Android 應用程式使用 Mobile SDK,請試用我們的 Sample App for Matter。
建構自己的應用程式
為協助您快速上手,我們已開放原始碼 Sample App for Matter,並提供相關的程式碼研究室,讓您為自己的 Android 專案自訂範例程式碼。
資源
如要進一步瞭解 Mobile SDK,請參閱 API 參考資料。
如要瞭解這個 SDK 如何處理使用者資料,請參閱 Home Mobile SDK Google Play「資料安全性」專區