1

We are trying to publish an Android Automotive app, but have some issues extending the CarAppService.

Disclaimer: I am very new to Android Automotive, so there might be an obvious answer to this question.

The code we are working on was developed by a previous team (which we don´t have contact with), and they have used Jetpack Compose for the application. Instead of CarAppService, they have used MainActivity, and instead of onGetTemplate, they have used setContent (code snippet below).

The function in MainActivity which implements the main component (Calculator())

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    carInfo = fetchCarInfo()
    fetchUxRestrictions()

    setContent {
        Theme {
            Calculator(this, isCarRestrictionNoSetup)
        }
    }
}

From the AndroidManifest.xml file:

 <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
                <category android:name="androidx.car.app.category.POI" />
            </intent-filter>
            <meta-data android:name="distractionOptimized" android:value="true" />
        </activity>

I have found very little documentation on the use of Jetpack Compose for Android Automotive, and in this video https://android-developers.googleblog.com/2021/03/android-auto-apps-powered-by-jetpack.html, at 09:38, its stated that "[...] currently and probably for forseeable future, you can only build apps relied on templates".

In the examples I have found online with CarAppService, onGetTemplate is always used to build and style the Android Automotive application.

After some research, I am growing certain that we can't use Jetpack Compose for the application, and that it has to be built on the predefined templates. If that is the case, my concern is that we have to scrap the code the previous team wrote and start over, which is why I want to ask here before I do anything.

My question is, is it possible to use Jetpack Compose to style an Android Automotive application, or do we have to use the templates?

Ank
  • 71
  • 6

2 Answers2

3

In general, it is not possible to use Jetpack Compose to write an application for Android Automotive OS that will be distributed via the Play Store. There are a few exceptions to this however:

  1. Video streaming apps can be written in either Views or Compose and do not use the Car App Library templating system
  2. The Settings/Sign In activities of Media applications can also use either Views or Compose.

One thing to note is that only the following category of apps are currently permitted on the Play Store for Android Automotive OS

  • Media
  • Point of Interest
  • Navigation
  • Video
Ben Sagmoe
  • 440
  • 2
  • 9
  • Thank you so much for your help! We have been researching so much without being able to find an answer. I am also wondering whether it is mandatory to use the templates? It appears that you can't implement CarAppService without eventually calling the onGetTemplate() function. But it is never specified in the documentation that you *have* to use the templates. – Ank Dec 06 '22 at 07:03
  • If you're using the Car App Library to write your app, you must use the templates to write your UI. This is for two main reasons - they reduce your effort as a developer since they handle reacting to the wide variety of screen sizes and orientations on your behalf and they are optimized to minimize driver distraction risks. – Ben Sagmoe Dec 06 '22 at 19:01
1

You have to use templates if you want your app to be accessible while driving. So for example, if you have a Point-Of-Interest app and want the driver to be able to search for restaurants while driving, you must use templates. the templates are optimized to reduce driver distraction and comply with the legal restrictions.

However, if you have an app that must not be used while driving (e.g. a video-streaming app) you can skip the templates.

Liz
  • 11
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 07 '23 at 05:04