IOT apps enable users to take relevant actions on connected devices from within the car. Examples include controlling the state of certain devices, such as opening a garage door, flipping home light switches, or enabling home security.
Declare category support in your manifest
Your app needs to declare the androidx.car.app.category.IOT
car app category in the intent
filter of its CarAppService
.
<application>
...
<service
...
android:name=".MyCarAppService"
android:exported="true">
<intent-filter>
<action android:name="androidx.car.app.CarAppService" />
<category android:name="androidx.car.app.category.IOT"/>
</intent-filter>
</service>
...
<application>
Implement your app's functionality
To implement your app, refer to Using the Android for Cars App Library on how Car App Library apps are built. Also, be sure to familiarize yourself with the Car App Quality Guidelines for IOT apps , as your app will be reviewed against these guidelines.
For IOT apps, the GridTemplate
is a great choice for displaying a list of devices and allowing the user to
interact with them, as shown in the following sample:
Kotlin
val listBuilder = ItemList.Builder() listBuilder.addItem( GridItem.Builder() .setTitle("Garage door") .setImage(...) // Handle user interactions .setOnClickListener {...} .build() ) listBuilder.addItem( GridItem.Builder() .setTitle("Garage lights") // Show a loading indicator until the status of the device is known // (call invalidate() when the status is known to refresh the screen) .setLoading(true) .build() ) return GridTemplate.Builder() .setTitle("Devices") .setHeaderAction(Action.APP_ICON) .setSingleList(listBuilder.build()) .build()
Java
ItemList.Builder listBuilder = new ItemList.Builder(); listBuilder.addItem( new GridItem.Builder() .setTitle("Garage door") .setImage(...) // Handle user interactions .setOnClickListener(() -> {...}) .build() ); listBuilder.addItem( new GridItem.Builder() .setTitle("Garage lights") // Show a loading indicator until the status of the device is known // (call invalidate() when the status is known to refresh the screen) .setLoading(true) .build() ); return new GridTemplate.Builder() .setTitle("Devices") .setHeaderAction(Action.APP_ICON) .setSingleList(listBuilder.build()) .build();