Android 專用的 Home Mobile SDK

為協助您建構與 Matter 裝置互動的 Android 應用程式,Google 開發了 Google Home Mobile SDK。Mobile SDK 包含兩個核心 API,可讓應用程式透過 Google Fabric 委託及共用裝置。

將裝置新增至 Google 結構體後,使用者就能透過 Google Home app (GHA)、Android 電源控制、語音和 Nest 觸控螢幕裝置控制裝置。

Mobile SDK 也可讓您定義自訂委任服務,用於將裝置委任給其他 Matter 生態系統。

將 Mobile SDK 整合至 Android 應用程式

如要開始使用,請完成下列步驟:

  1. 請按照「設定 Google Play services」中的指示操作。

  2. 將 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 支援,請在 AndroidManifest.xml 檔案的 application 宣告中加入下列 service 區塊:

<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 上篩選套件瀏覽權限」一文。

使用 Google Home Matter 範例應用程式

如要瞭解 Mobile SDK 如何在 Android 應用程式中運作,請試用我們的 Sample App for Matter。

試用 Sample App for Matter

建構自己的應用程式

為協助您快速上手,我們已開放 Sample App for Matter 的原始碼,並提供隨附的程式碼實驗室,讓您能根據自己的 Android 專案自訂範例程式碼。

前往 Sample App for Matter 程式碼實驗室

資源

如要進一步瞭解 Mobile SDK,請參閱 API 參考資料。

如要瞭解這個 SDK 如何處理使用者資料,請參閱 Home Mobile SDK 的 Google Play 資料安全性專區