為了協助您建構與 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 應用程式,以確保 Matter 支援應用程式使用者,請將下列 service
區塊新增至 AndroidManifest.xml
檔案中的 application
宣告:
<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>
這個選項僅適用於搭載 Play services 22.50.14 以上版本的 Android 裝置。
如需實作範例,請參閱 Sample App for Matter 的資訊清單。
您可以在執行階段使用 ModuleInstallClient
查看首頁模組的可用性。詳情請參閱「使用 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 上篩選套件瀏覽權限。
使用 Matter 的 Google Home 範例應用程式
如要瞭解 Mobile SDK 在 Android 應用程式中的運作方式,請嘗試我們的 Sample App for Matter。
建構自己的應用程式
為了協助您快速上手,我們開啟了 Sample App for Matter 並提供隨附程式碼研究室,方便您自訂 Android 專案的程式碼範例。
前往 Sample App for Matter 程式碼研究室
資源
如要進一步瞭解 Mobile SDK,請參閱 API 參考資料。
如要瞭解這個 SDK 如何處理使用者資料,請參閱 Home Mobile SDK Google Play 資料安全性專區。