Build an Android App with Google Home APIs: Devices, Structures, and Commissioning
Google for DevelopersJune 12, 202512 min7,151 views
25 connectionsΒ·40 entities in this videoβSetting Up Your Development Environment
- π‘ Ensure you have the latest Android Studio installed, an Android phone with Google Play Services and the Google Home app, and a compatible Google Home Hub for Matter devices.
- π οΈ For virtual devices, refer to the developer center for setup instructions and linking your device to the Google Home app.
- π Clone the sample app source code from GitHub and locate the
to-doblocks in the comments where you will add code. - π Connect your physical Android phone to Android Studio, enabling USB debugging in developer options if needed.
Authentication and Permissions
- π The Home APIs use OAuth 2.0 for authentication, allowing users to grant permissions without exposing login credentials.
- βοΈ Set up your OAuth consent screen in the Google Cloud console, choosing between internal or external use cases and adding test users.
- π± Register your sample app for OAuth 2.0, ensuring you indicate the application type as an Android app.
- βοΈ Initialize the SDK by defining supported device types and traits in the
home_app.ktfile and configuring thehome_clientobject. - β
Implement the
checkPermissionsandrequestPermissionsfunctions in thepermissions_manager.ktfile to handle user permissions.
Device and Structure APIs
- π The Home API data model consists of structures (homes), rooms, devices, device types, traits, and automations.
- π Structures contain rooms, which in turn contain devices. Devices are composed of device types and traits.
- π Use Kotlin Flows to stream data model objects; subscribe to the
structuresfunction to get a flow of structures and then calllistto retrieve all owned structures. - π± In the
home_app_view_model.ktfile, implement code to subscribe to structure changes and store view models, selecting the first structure if none is selected. - ποΈ Render the structure list as a drop-down menu in the
devices_view.ktfile by subscribing to the structure view model state flow. - π‘ To retrieve device states, subscribe to the device type flow. Each device has supported types and traits that define its capabilities.
- π Implement
to-doblocks in thedevice_view_model.ktto determine primary types and get supported traits, then render an on-off trait in thedevice_view.ktfile. - πΉοΈ Issue commands to devices using convenience functions on trait objects, such as
trait.on()ortrait.moveToLevel().
Commissioning Matter Devices
- π The commissioning API allows you to add Matter devices to the Google Home ecosystem.
- β οΈ This section requires a Matter device and a compatible Google Hub that supports Matter.
- π Set up two variables for the commissioning API: an
ActivityResultLauncherto send the commissioning intent and manage callbacks, andcommissioningResultto store the outcome. - π² Build and launch the commissioning intent, ideally within a dedicated function tied to a UI element like an "Add Device" button.
- π€³ Running the app will display an "Add Device" button that initiates the commissioning flow, including QR code scanning, user agreement, device discovery, and naming.
- β Upon completion, control is returned to the app with the commissioning result passed back to the callback function.
Knowledge graph40 entities Β· 25 connections
How they connect
An interactive map of every person, idea, and reference from this conversation. Hover to trace connections, click to explore.
Hover Β· drag to explore
40 entities
Chapters6 moments
Key Moments
Transcript47 segments
Full Transcript
Topics13 themes
Whatβs Discussed
Google Home APIsAndroid DevelopmentSmart HomeMatter DevicesCommissioning APIDevice APIStructure APIOAuth 2.0AuthenticationPermissions APIAndroid StudioKotlin FlowsSDK Initialization
Smart Objects40 Β· 25 links
ProductsΒ· 23
ConceptsΒ· 14
PersonΒ· 1
CompaniesΒ· 2