Reputation: 39
I have created a first Hello World App for Android Auto from "No Activity" template for Android Automotive.
In Launch Options I had to choose nothing. The build was successful and Android Studio reported "Launch succeeded".
But in the DHU no Launcher Icon for the App is visible.
Even after closing the DHU, stopped the development server in Android Auto, killed Android, restarted it, restarted the dev server in Auto and DHU no Launch Icon appears.
My AndroidManifest.xml is defined with
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.oliverkarst.fastccschargers">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="androidx.car.app.NAVIGATION_TEMPLATES"/>
<uses-permission android:name="androidx.car.app.ACCESS_SURFACE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-feature android:name="android.hardware.type.automotive" android:required="true" />
<uses-feature android:name="android.software.car.templates_host" />
<application>
<service
android:name=".HelloWorldService"
android:exported="true"
android:label="Fast CCS Chargers"
android:icon="@mipmap/ic_launcher">
<intent-filter>
<action android:name="androidx.car.app.CarAppService" />
<category android:name="androidx.car.app.category.CHARGING"/>
</intent-filter>
</service>
<meta-data
android:name="androidx.car.app.minCarApiLevel"
android:value="1" />
</application>
</manifest>
The HelloWorldService.kt is defined as
package de.oliverkarst.fastccschargers
import android.content.pm.ApplicationInfo
import androidx.car.app.CarAppService
import androidx.car.app.Session
import androidx.car.app.validation.HostValidator
class HelloWorldService : CarAppService() {
override fun createHostValidator(): HostValidator {
return if (applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE != 0) {
HostValidator.ALLOW_ALL_HOSTS_VALIDATOR
} else {
HostValidator.Builder(applicationContext)
.addAllowedHosts(androidx.car.app.R.array.hosts_allowlist_sample)
.build()
}
}
override fun onCreateSession(): Session {
return HelloWorldSession()
}
}
HelloWorldSession.kt
package de.oliverkarst.fastccschargers
import android.content.Intent
import androidx.car.app.Screen
import androidx.car.app.Session
class HelloWorldSession() : Session() {
override fun onCreateScreen(intent: Intent): Screen {
return HelloWorldScreen(carContext)
}
}
HelloWorldScreen.kt
package de.oliverkarst.fastccschargers
import androidx.car.app.CarContext
import androidx.car.app.Screen
import androidx.car.app.model.*
class HelloWorldScreen(carContext: CarContext) : Screen(carContext) {
override fun onGetTemplate(): Template {
val row = Row.Builder().setTitle("Hello").build()
val pane = Pane.Builder().addRow(row).build()
return PaneTemplate.Builder(pane)
.setHeaderAction(Action.APP_ICON)
.build()
}
}
I created only the Automotive Modul. No mobile module. Could it be that I have to create and install that first?
Does anyone has an idea what I am doing wrong?
I followed the instructions from here https://developer.android.com/training/cars/apps/navigation
Upvotes: 0
Views: 1077
Reputation: 47
I recommend looking at the car_samples and specifically manifest files of apps. After numerous tries, I think it's important to add the following meta-data to your manifest on top of what you have already:
<meta-data android:name="com.google.android.gms.car.application"
android:resource="@xml/automotive_app_desc"
tools:ignore="MetadataTagInsideApplicationTag" />
And resource file as follows:
<?xml version="1.0" encoding="utf-8"?>
<automotiveApp xmlns:android="http://schemas.android.com/apk/res/android">
<uses name="template" />
</automotiveApp>
After that install the app, restart DHU try if it shows up.
I didn't manage to find though all descriptions and logic on what blocks should be added to automotive_app_desc though.
Upvotes: 1