This is small sample project to show how you can add android auto support to your project. In this particular case is a media app, but of course you can create other such a message or navigation app.
I recommend this great tutorial to understand deeper https://proandroiddev.com/android-auto-tutorial-step-by-step-guide-50bb6b73e2b8
Add to your manifest
<meta-data
android:name="com.google.android.gms.car.application"
android:resource="@xml/automotive_app_desc" />
<service android:name=".service.MediaService"
android:exported="true">
<intent-filter>
<action android:name="android.media.browse.MediaBrowserService" />
</intent-filter>
</service>
automotive_app_desc.xml
<?xml version="1.0" encoding="utf-8"?>
<automotiveApp>
<uses name="media" />
</automotiveApp>
To support voice actions you need to implement onPlayFromSearch method in your media session callback.
override fun onPlayFromSearch(query: String?, extras: Bundle?) {
super.onPlayFromSearch(query, extras)
}
To test your app you need to install the desktop head unit, install it following this instructions https://developer.android.com/training/cars/testing/dhu

This is how it looks the sample app, notice that you dont have to create any view, android does it for you, all you have to do is pass it the necessary data to media session and thats it.
I hope it has been useful to you 🫶