사물 인터넷 앱 빌드

IOT 앱을 통해 사용자는 차 안에서 연결된 기기를 대상으로 관련 작업을 실행할 수 있습니다. 그 예로 차고 문 열기, 홈 조명 스위치 켜거나 끄기, 홈 보안 사용 설정하기 등 특정 기기의 상태를 제어하는 작업을 들 수 있습니다.

매니페스트에서 카테고리 지원 선언

앱은 CarAppService의 인텐트 필터에서 androidx.car.app.category.IOT 자동차 앱 카테고리를 선언해야 합니다.

<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>

앱 기능 구현

앱을 구현하려면 자동차용 Android 앱 라이브러리 사용에서 자동차 앱 라이브러리 앱이 빌드되는 방식을 참고하세요. 또한 앱의 검토 기준이 되는 IOT 앱용 자동차 앱 품질 가이드라인을 숙지하세요.

IoT 앱에서는 다음 샘플에서처럼 GridTemplate을 사용하면 기기 목록을 표시하고 사용자가 기기와 상호작용하도록 할 수 있습니다.

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();