관심 장소 앱 빌드

이 가이드에서는 관심 장소 앱의 기능을 구현하는 데 활용할 수 있는 자동차 앱 라이브러리의 다양한 기능을 자세하게 설명합니다.

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

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

다음 예는 앱 카테고리를 선언하는 방법을 보여줍니다.

<application>
    ...
   <service
       ...
        android:name=".MyCarAppService"
        android:exported="true">
      <intent-filter>
        <action android:name="androidx.car.app.CarAppService" />
        <category android:name="androidx.car.app.category.POI"/>
      </intent-filter>
    </service>
    ...
<application>

지도 템플릿에 액세스

앱은 호스트에 의해 렌더링된 지도와 함께 관심 장소 목록을 표시하도록 특별히 설계된 PlaceListMapTemplate에 액세스할 수 있습니다.

이 템플릿에 액세스하려면 앱이 AndroidManifest.xml 파일에 androidx.car.app.MAP_TEMPLATES 권한을 선언해야 합니다.

<uses-permission android:name="androidx.car.app.MAP_TEMPLATES"/>

PlaceListMapTemplate 콘텐츠 새로고침

운전자가 PlaceListMapTemplate으로 빌드된 장소 목록을 탐색하면서 버튼 하나만 탭하여 콘텐츠를 새로고침하도록 할 수 있습니다. OnContentRefreshListener 인터페이스의 onContentRefreshRequested 메서드를 구현하고, PlaceListMapTemplate.Builder.setOnContentRefreshListener를 사용하여 템플릿의 리스너가 목록 새로고침을 사용하도록 설정합니다.

다음 스니펫은 템플릿의 리스너를 설정하는 방법을 보여줍니다.

Kotlin

PlaceListMapTemplate.Builder()
    ...
    .setOnContentRefreshListener {
        // Execute any desired logic
        ...
        // Then call invalidate() so onGetTemplate() is called again
        invalidate()
    }
    .build()

Java

new PlaceListMapTemplate.Builder()
        ...
        .setOnContentRefreshListener(() -> {
            // Execute any desired logic
            ...
            // Then call invalidate() so onGetTemplate() is called again
            invalidate();
        })
        .build();

새로고침 버튼은 리스너에 값이 있는 경우에만 PlaceListMapTemplate의 헤더에 표시됩니다.

사용자가 새로고침 버튼을 클릭하면 OnContentRefreshListener 구현의 onContentRefreshRequested 메서드가 호출됩니다. onContentRefreshRequested 내에서 Screen.invalidate 메서드를 호출합니다. 그러면 호스트는 앱의 Screen.onGetTemplate 메서드를 다시 호출하여, 새로고침된 콘텐츠가 포함된 템플릿을 가져옵니다. 템플릿 새로고침에 관한 자세한 내용은 템플릿 콘텐츠 새로고침을 참고하세요. onGetTemplate에서 반환된 다음 템플릿이 동일한 유형인 경우 새로고침으로 집계되며 템플릿 할당량에 포함되지 않습니다.

앱 작업을 사용하여 Google 어시스턴트와 통합

어시스턴트를 사용하여 관심 장소 앱을 음성으로 사용 설정하면 사용자가 "Hey Google, ExampleApp에서 근처 충전소 찾아 줘"와 같이 말하여 관심 장소를 검색할 수 있습니다. 자세한 내용은 자동차용 앱 작업을 참고하세요.