이 섹션에서는 관심 장소(POI) 앱의 기능을 구현하는 데 활용할 수 있는 라이브러리의 다양한 기능을 자세하게 설명합니다.
매니페스트에서 카테고리 지원 선언
앱은 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()
자바
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 어시스턴트와 통합
앱 작업을 사용하면 사용자가 Google 어시스턴트를 사용하여 음성으로 Android 앱을 실행하고 제어할 수 있습니다. 앱 작업 기능을 추가하여 어시스턴트를 관심 장소 앱과 통합할 수 있습니다. 기능은 앱의 관련 기능을 표현한 것으로 내장 인텐트(BII)와 처리 과정을 포함합니다. 예를 들어 사용자가 "Hey Google, ExampleApp에서 거리에 있는 주차장 찾아 줘"라고 말하면 앱에 적절한 화면이 열립니다.
제한사항
앱 작업에는 다음과 같은 제한사항이 있습니다.
- 관심 장소 카테고리에서 자동차 앱 라이브러리를 사용하는 앱에서만 사용할 수 있습니다.
- 음성 지원은 주차 또는 충전 내장 인텐트에만 지원됩니다.
- 앱 작업 처리는 딥 링크로만 실행이 가능합니다.
통합 단계
AndroidManifest.xml
파일의<application>
요소에 다음<meta-data>
요소를 추가합니다.<meta-data android:name="android.app.shortcuts" android:resource="@xml/shortcuts" />
어시스턴트가 딥 링크로 앱 콘텐츠에 연결할 수 있으려면
AndroidManifest.xml
파일에<intent-filter>
요소가 있어야 합니다.Android Auto의 경우 intent-filter가 모바일 앱과 동일합니다.
Android Automotive OS 처리의 경우 앱 작업은
CarAppService
세션에 의해 트리거됩니다. 세션이 딥 링크를 트리거하도록 허용하려면AndroidManifest.xml
파일의<activity>
요소에 인텐트 필터를 지정해야 합니다.
<activity ... android:name="androidx.car.app.activity.CarAppActivity"> … <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="YOUR_SCHEME" android:host="YOUR_HOST" /> </intent-filter> </activity>
적절한 기능을 사용하여 앱 프로젝트의
res/xml
디렉터리에shortcuts.xml
파일을 만듭니다.<?xml version="1.0" encoding="utf-8"?> <shortcuts xmlns:android="http://schemas.android.com/apk/res/android"> <!-- Your Capability definitions will go here --> </shortcuts>
세션의 처리를 해결하도록 앱을 업데이트합니다.
다음은
Session.onCreateScreen
및Session.onNewIntent
의 인텐트 처리 샘플입니다.onCreateScreen
Kotlin
@Override fun onCreateScreen(@NonNull intent: Intent): Screen { if (intent.getData() != null) { val uri: Uri = intent.getData() // uri = "YOUR_SCHEME://YOUR_HOST?name=Levis%20center" // Build your Templates with parsed uri parameters ... } }
자바
@Override public Screen onCreateScreen(@NonNull Intent intent) { if (intent.getData() != null) { Uri uri = intent.getData(); // uri = "YOUR_SCHEME://YOUR_HOST?name=Levis%20center" // Build your Templates with parsed uri parameters … } }
onNewIntent
Kotlin
@Override fun onNewIntent(@NonNull intent: Intent): Screen { if (intent.getData() != null) { val uri: Uri = intent.getData() // uri = "YOUR_SCHEME://YOUR_HOST?name=Levis%20center" // Build your Templates with parsed uri parameters … } }
자바
@Override public void onNewIntent(@NonNull Intent intent) { if (intent.getData() != null) { Uri uri = intent.getData(); // uri = "YOUR_SCHEME://YOUR_HOST?name=Levis%20center" // Build your Templates with parsed uri parameters … } }
기능
앱 작업은 다음 기능을 지원합니다.
주차
작업 ID: actions.intent.GET_PARKING_FACILITY
설명: 주차 시설을 가져옵니다. 주차 유형, 앱 이름, 위치를 지정할 수 있습니다.
언어 지원: ko-KR
매개변수:
parkingFacility.disambiguatingDescription
- 주차 유형에 대한 설명어(예: '무료', '대리' 또는 '거리'). 이 매개변수를 사용하면 주차 시설 유형을 필터링할 수 있습니다.- 다음 매개변수는 사용자가 요청한 주차 시설의 위치를 확인하는 데 도움이 됩니다. 다음의 매개변수의 값이 하나도 없는 경우 사용자의 현재 위치와 가장 가까운 시설을 반환해야 합니다.
parkingFacility.name
- 시설 위치의 이름(예: 'Mountain View')parkingFacility.address
- 시설 위치의 주소(예: '123 Easy St, Mountain View, CA')parkingFacility.geo.latitude
- 시설의 위도(예: '37.3861')parkingFacility.geo.longitude
- 시설의 경도(예: '-122.084')
샘플 capability
정의:
<?xml version="1.0" encoding="utf-8"?>
<!-- This is a sample shortcuts.xml -->
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<capability android:name="actions.intent.GET_PARKING_FACILITY">
<intent>
<url-template
android:value="YOUR_SCHEME://YOUR_HOST{?name,address,disambiguatingDescription,latitude,longitude}">
<!-- Eg. name = "Googleplex" -->
<parameter
android:name="parkingFacility.name"
android:key="name"/>
<!-- Eg. address = "1600 Amphitheatre Pkwy, Mountain View, CA 94043" -->
<parameter
android:name="parkingFacility.address"
android:key="address"/>
<!-- Eg. disambiguatingDescription = "valet" -->
<parameter
android:name="parkingFacility.disambiguatingDescription"
android:key="disambiguatingDescription"/>
<!-- Eg. latitude = "37.3861" -->
<parameter
android:name="parkingFacility.geo.latitude"
android:key="latitude"/>
<!-- Eg. longitude = "-122.084" -->
<parameter
android:name="parkingFacility.geo.longitude"
android:key="longitude"/>
</intent>
</capability>
</shortcuts>
충전
작업 ID: actions.intent.GET_CHARGING_STATION
설명: 충전소를 가져옵니다. 앱 이름 또는 위치를 지정할 수도 있습니다.
언어 지원: ko-KR
매개변수:
chargingStation.disambiguatingDescription
- 충전소 유형을 나타내는 설명어(예: '무료', '유료'). 이 매개변수를 사용하여 충전소 유형을 필터링할 수 있습니다.- 다음 매개변수는 사용자가 요청한 충전소의 위치를 확인하는 데 도움이 됩니다. 다음 매개변수의 값이 하나도 경우 사용자의 현재 위치와 가장 가까운 충전소를 반환해야 합니다.
chargingStation.name
- 충전소 위치의 이름(예: 'Mountain View')chargingStation.address
- 충전소 위치의 주소(예: '123 Easy St, Mountain View, CA')chargingStation.geo.latitude
- 충전소의 위도(예: '37.3861')chargingStation.geo.longitude
- 충전소의 경도(예: '-122.084')
샘플 capability
정의:
<?xml version="1.0" encoding="utf-8"?>
<!-- This is a sample shortcuts.xml -->
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<capability android:name="actions.intent.GET_CHARGING_STATION">
<intent>
<url-template
android:value="YOUR_SCHEME://YOUR_HOST{?name,address,latitude,longitude,type}">
<!-- Eg. name = "Googleplex" -->
<parameter
android:name="chargingStation.name"
android:key="name"/>
<!-- Eg. address = "1600 Amphitheatre Pkwy, Mountain View, CA 94043" -->
<parameter
android:name="chargingStation.address"
android:key="address"/>
<!-- Eg. latitude = "37.3861" -->
<parameter
android:name="chargingStation.geo.latitude"
android:key="latitude"/>
<!-- Eg. longitude = "-122.084" -->
<parameter
android:name="chargingStation.geo.longitude"
android:key="longitude"/>
</intent>
</capability>
</shortcuts>