Android Question ANDROID-AUTO

Mr Blue Sky

Active Member
Licensed User
Longtime User
Hello everyone in the B4A community,

I'm developing an test app for Android Auto and I'm facing a few problem. My goal is to make the app viewable both on Android Auto and as a regular app on smartphones. Here is how I configured my manifest:

manifest:
AddManifestText(
<uses-sdk android:minSdkVersion="23" android:targetSdkVersion="33"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>
   
<application
    android:allowBackup="true"
    android:appCategory="productivity"
    android:icon="@drawable/icon"
    android:label="android_auto"
    android:supportsRtl="true"
    android:theme="@style/LightTheme">
    <meta-data
        android:name="com.google.android.gms.car.application"
        android:resource="@xml/automotive_app_desc"/>
</application>

<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT"/>
<uses-permission android:name="android.permission.BLUETOOTH_SCAN"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE"/>
<uses-permission android:name="android.permission.NEARBY_WIFI_DEVICES"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-feature android:name="android.hardware.type.automotive" android:required="true" />
<uses-feature android:name="android.hardware.wifi" android:required="false" />
<uses-feature android:name="android.hardware.screen.portrait" android:required="false" />
<uses-feature android:name="android.hardware.screen.landscape" android:required="true" />
)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.LightTheme)

The installation is successful, and the application appears in "System > My applications" but not in the phone's launcher. Additionally, when I add a necessary intent-filter to the main activity for visibility in the launcher, I receive an "invalid package" error message.
Also, in both configurations, the application is not visible in the Android Auto launcher either.

Do you have any suggestions or solutions to resolve these issues? Examples of configurations that have worked for you would be much appreciated.

Thanks a lot for your help !

splash1.jpg

with
android:name="com.google.android.gms.car.application"
android:resource="@xml/automotive_app_desc"/>

splash2.jpg

without

splash3.jpg
 

Mr Blue Sky

Active Member
Licensed User
Longtime User
Check the generated Objects\AndroidManifest.txt file. You will see that you have two Application nodes.

Use AddApplicationText to add the meta-data element.
Thanks Erel, I seem to have fixed it following your instructions, now the application works on the phone but is still not visible from the Android auto application launcher, something must definitely be missing.

AndroidManifest.xml

manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    package="b4a.android_auto"
    android:versionCode="1"
    android:versionName="android_auto"
    android:installLocation="internalOnly">
    
    <uses-sdk android:minSdkVersion="23" android:targetSdkVersion="33"/>
        <supports-screens android:largeScreens="true"
            android:normalScreens="true"
            android:smallScreens="true"
            android:anyDensity="true"/>
        
    <application
            android:allowBackup="true"
            android:appCategory="productivity"
            android:icon="@drawable/icon"
            android:label="android_auto"
            android:supportsRtl="true"
            android:theme="@style/LightTheme">
            <meta-data
                android:name="com.google.android.gms.car.application"
                android:resource="@xml/automotive_app_desc"/>
            <activity
                android:windowSoftInputMode="stateHidden"
                android:launchMode="singleTop"
                android:name=".main"
                android:label="android_auto"
                android:screenOrientation="landscape"
                android:exported="true">
                <intent-filter>
                   <action android:name="android.intent.action.MAIN" />
                   <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            <service
                android:name=".starter"
                android:exported="true">
            </service>
            <receiver
                android:name=".starter$starter_BR"
                android:exported="true">
            </receiver>
    </application>
    
        <uses-permission android:name="android.permission.BLUETOOTH"/>
        <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
        <uses-permission android:name="android.permission.BLUETOOTH_CONNECT"/>
        <uses-permission android:name="android.permission.BLUETOOTH_SCAN"/>
        <uses-permission android:name="android.permission.BLUETOOTH_ADvertise"/>
        <uses-permission android:name="android.permission.NEARBY_WIFI_DEVICES"/>
        <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
        <uses-permission android:name="android.permission.WAKE_LOCK"/>
        <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
    
    <uses-feature android:name="android.hardware.type.automotive" android:required="true" />
    <uses-feature android:name="android.hardware.wifi" android:required="false" />
    <uses-feature android:name="android.hardware.screen.portrait" android:required="false" />
    <uses-feature android:name="android.hardware.screen.landscape" android:required="true" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
    <application
        android:icon="@drawable/icon"
        android:label="android_auto"
        android:theme="@style/LightTheme">
        <activity
            android:windowSoftInputMode="stateHidden"
            android:launchMode="singleTop"
            android:name=".main"
            android:label="android_auto"
            android:screenOrientation="landscape"
            android:exported="true">
            <intent-filter>
               <action android:name="android.intent.action.MAIN" />
               <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            
        </activity>
        <service
            android:name=".starter"
            android:exported="true">
        </service>
        <receiver
            android:name=".starter$starter_BR"
            android:exported="true">
        </receiver>
    </application>
</manifest>

automotive_app_desc.xml

automotive_app_desc:
<?xml version="1.0" encoding="utf-8"?>
<automotiveApp xmlns:android="http://schemas.android.com/apk/res/android">
    <uses name="notification"/>
    <uses name="media"/>
</automotiveApp>

Do you have any suggestions or solutions to resolve these issues? Examples of configurations that have worked for you would be much appreciated

splash4.jpg
 
Upvote 0

Mr Blue Sky

Active Member
Licensed User
Longtime User
Remove the XML file and add it with:
B4X:
CreateResource(xml, automotive_app_desc.xml,
<automotiveApp xmlns:android="http://schemas.android.com/apk/res/android">
    <uses name="notification"/>
    <uses name="media"/>
</automotiveApp>)

Or make sure that the file is read only.
sorry Erel I didn't really understand your answer in (Remove the XML file and add it with) as for the automotive_app_desc file this one is read only
splash5.jpg
 
Last edited:
Upvote 0

Mr Blue Sky

Active Member
Licensed User
Longtime User
I've searched everywhere on the forums and haven't found anything conclusive. I'm wondering if it's possible to make our apps compatible with Android Auto, not to be confused with Automotive OS. No example we must believe that people not have succeeded since the release of the product

manifest
manifest:
AddManifestText(
<uses-sdk android:minSdkVersion="23" android:targetSdkVersion="33"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>

<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT"/>
<uses-permission android:name="android.permission.BLUETOOTH_SCAN"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADvertise"/>
<uses-permission android:name="android.permission.NEARBY_WIFI_DEVICES"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-feature android:name="android.hardware.type.automotive" android:required="true" />
<uses-feature android:name="android.hardware.wifi" android:required="false" />
<uses-feature android:name="android.hardware.screen.portrait" android:required="false" />
<uses-feature android:name="android.hardware.screen.landscape" android:required="true" />

<application
    android:allowBackup="true"
    android:appCategory="productivity"
    android:icon="@drawable/icon"
    android:label="android_auto"
    android:supportsRtl="true"
    android:theme="@style/LightTheme">

    <meta-data
        android:name="com.google.android.gms.car.application"
        android:resource="@xml/automotive_app_desc"/>
    <activity
        android:name=".main"
        android:label="android_auto"
        android:icon="@drawable/icon"
        android:theme="@style/LightTheme"
        android:windowSoftInputMode="stateHidden"
        android:launchMode="singleTop"
        android:screenOrientation="landscape"
        android:exported="true">
        <intent-filter>
           <action android:name="android.intent.action.MAIN" />
           <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <service
        android:name=".starter"
        android:exported="true">
    </service>
    <receiver
        android:name=".starter$starter_BR"
        android:exported="true">
    </receiver>
    <service android:name=".MyMediaBrowserService"
             android:exported="true">
        <intent-filter>
            <action android:name="android.media.browse.MediaBrowserService"/>
        </intent-filter>
    </service>
</application>
)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.LightTheme)

file is read only.
automotive_app_desc:
<?xml version="1.0" encoding="utf-8"?>
<automotive-app>
    <template>
        <usage name="navigation"/>
        <usage name="media"/>
    </template>
</automotive-app>
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
I have the impression that the result from the Android Auto app on my phone is projected onto my screen of an Android Auto compatible screen in my car via the USB cable or via Bluetooth.

Not every car and radio can work with Android Auto. Here you can find a list of Compatible vehicles and radios.

And here is Set up Android Auto

And below is the XML manifest file for Android Auto 11.9.641804-release (arm64-v8a) (Android 8.0+).
 

Attachments

  • AndroidManifest.xml
    91.6 KB · Views: 126
Upvote 0

Mr Blue Sky

Active Member
Licensed User
Longtime User
I have the impression that the result from the Android Auto app on my phone is projected onto my screen of an Android Auto compatible screen in my car via the USB cable or via Bluetooth.

Not every car and radio can work with Android Auto. Here you can find a list of Compatible vehicles and radios.

And here is Set up Android Auto

And below is the XML manifest file for Android Auto 11.9.641804-release (arm64-v8a) (Android 8.0+).
Thank MicroDrie, it is not for use in a car, I just want to be able to have an interface on this screen compatible with carplay and android auto so as to transmit some information to it on its display.
 
Last edited:
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
Too bad, I also tried it today, without success.
My app is not displayed in Android Auto.
Have you also enabled the developer option in the Android Auto settings?
  1. You turn this on by frequently tapping the Version item (the last one) in Android Auto settings to unlock the developer settings.
  2. Then tap the Developer Settings menu item and enable Unknown Sources.
  3. Restart Android Auto and if your app is fine it will be listed.
 
Upvote 0

Mr Blue Sky

Active Member
Licensed User
Longtime User
Have you also enabled the developer option in the Android Auto settings?
  1. You turn this on by frequently tapping the Version item (the last one) in Android Auto settings to unlock the developer settings.
  2. Then tap the Developer Settings menu item and enable Unknown Sources.
  3. Restart Android Auto and if your app is fine it will be listed.
sorry still nothing, I am in developer mode on android and android auto and I have also enabled the activation of unknown sources android auto as well.
I'm using Android 14 on my phone, is this a problem?
Do you have a simple working example with just a "hello" button for B4A on Android Auto
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
  1. I'm using Android 14 on my phone, is this a problem?

  2. Do you have a simple working example with just a "hello" button for B4A on Android Auto
  1. I also have Samsung Galaxy A13 Android 14 on my phone and recently I've been having problems with the USB connection between the phone and my IDE development PC. I can now connect via the WLAN via B4A Bridge.

  2. Unfortunately not yet, but it seems interesting to me. Now that I think about it, even in the car (Opel Corsa) I had also to convert my USB connection to a Bluetooth connection to use Google maps from my Samsung Galaxy A53 5G Android 14 phone.
 
Upvote 0

Filippo

Expert
Licensed User
Longtime User
Hi,

I have managed to make my app visible on my Android car.

Unfortunately, the app is only seen as a messaging app and does not show the proper app functionality.
I have already tested many settings, unfortunately always without success.

I have added the following entries in the manifest:
B4X:
CreateResource(xml, automotive_app_desc.xml,
<automotiveApp xmlns:android="http://schemas.android.com/apk/res/android">
    <uses name="notification"/>
    <uses name="media"/>
</automotiveApp>)
AddApplicationText(<meta-data
    android:name="com.google.android.gms.car.application"
    android:resource="@xml/automotive_app_desc"/>
    android:name="com.android.automotive"
)
AddManifestText(
    <uses-feature android:name="android.hardware.type.automotive"
    android:required="true"/>
    <uses-feature android:name="android.software.car.templates_host"
    android:required="true"/>
    <uses-feature android:name="android.hardware.screen.landscape"
    android:required="false"/>
    <uses-feature android:name="android.hardware.wifi"
    android:required="false"/>
    <uses-feature android:name="android.hardware.screen.portrait"
    android:required="false"/>
    <uses-feature android:name="android.hardware.camera"
    android:required="false"/>
)
AddApplicationText(
    android:exported="true"
    android:theme="@android:style/Theme.DeviceDefault.NoActionBar"
    android:name="androidx.car.app.activity.CarAppActivity"
    android:launchMode="singleTask"
    android:label="Speedpilot">

    <meta-data android:name="distractionOptimized" android:value="true" />
)
AddActivityText(Main,
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
)
AddActivityText(Main,
    <intent-filter>
        <action android:name="androidx.car.app.CarAppService" />
        <category android:name="androidx.car.app.category.NAVIGATION" />
    </intent-filter>
)

1718181347759.png


1718181365069.png
 
Upvote 0

Mr Blue Sky

Active Member
Licensed User
Longtime User
Unfortunately, it doesn't work, or I'm doing something wrong.
The whole Android-auto system is not easy to understand.
Well I'm struggling like crazy but here's what I can do for the moment (not much, but the application is already running)

1.jpg

2.jpg


manifest
manifest:
' This code will be applied to the manifest file during compilation.
' You do not need to modify it in most cases.
' See this link for more information: https://www.b4x.com/forum/showthread.php?p=78136

' Default manifest and application settings:
AddManifestText(
    ' Specifies the minimum and target versions of the Android SDK
    <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="33"/>
    ' Supports different screen sizes and densities
    <supports-screens android:largeScreens="true"
        android:normalScreens="true"
        android:smallScreens="true"
        android:anyDensity="true"/>
)
' Set app icon
SetApplicationAttribute(android:icon, "@drawable/icon")
' Set the application label
SetApplicationAttribute(android:label, "$LABEL$")
' Create a resource from a theme file
CreateResourceFromFile(Macro, Themes.LightTheme)

' Permissions required for the application
AddPermission(android.permission.ACCESS_FINE_LOCATION) ' Access to precise location
AddPermission(android.permission.BLUETOOTH_SCAN) ' Bluetooth permissions to scan, connect, and stream
AddPermission(android.permission.BLUETOOTH_CONNECT)
AddPermission(android.permission.BLUETOOTH_ADVERTISE)
AddPermission(android.permission.NEARBY_WIFI_DEVICES) ' Permission to access nearby Wi-Fi devices
AddPermission(android.permission.WRITE_EXTERNAL_STORAGE) ' Permission to write to external storage
AddPermission(android.permission.WAKE_LOCK) ' Permission to prevent the device from going to sleep

AddPermission(android.permission.INTERNET) ' Common permissions for Internet access
AddPermission(android.permission.ACCESS_NETWORK_STATE) ' Permission for network state

' Permission for notifications
AddPermission(android.permission.ACCESS_NOTIFICATION_POLICY)
AddPermission("android.permission.POST_NOTIFICATIONS")
AddPermission("android.permission.RECEIVE_BOOT_COMPLETED") ' receive notifications when the device starts

' Define resources specific to automotive applications
CreateResource(xml, automotive_app_desc.xml,
    <automotiveApp xmlns:android="http://schemas.android.com/apk/res/android">
        <uses name="template"/>
        <uses name="notification"/>
        <uses name="navigation"/>
        <uses name="media"/>
    </automotiveApp>
)

' Metadata for the Google Automotive app
AddApplicationText(
    <meta-data
        android:name="com.google.android.gms.car.application"
        android:resource="@xml/automotive_app_desc"/>
    android:name="com.android.automotive"
)

' Additional entries in the manifest to specify device features and requirements
AddManifestText(
    <uses-feature android:name="android.hardware.type.automotive" android:required="true"/>
    <uses-feature android:name="android.software.car.templates_host" android:required="true"/>
    <uses-feature android:name="android.hardware.screen.landscape" android:required="false"/>
    <uses-feature android:name="android.hardware.wifi" android:required="false"/>
    <uses-feature android:name="android.hardware.screen.portrait" android:required="false"/>
    <uses-feature android:name="android.hardware.camera" android:required="false"/>
)

' Configuring the main application activity for automotive use
AddApplicationText(
    android:exported="true"
    android:theme="@android:style/Theme.DeviceDefault.NoActionBar"
    android:name="androidx.car.app.activity.CarAppActivity"
    android:launchMode="singleTask"
    android:label="aeonauto">
    <meta-data android:name="distractionOptimized" android:value="true" />
)

' Intent-filters for main activity for MAIN and navigation
' Intent-filter to launch the application
AddActivityText(Main,
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
)

 ' Intent-filter for car navigation service
AddActivityText(Main,
    <intent-filter>
        <action android:name="androidx.car.app.CarAppService" />
        <category android:name="androidx.car.app.category.NAVIGATION" />
    </intent-filter>
)

B4X Main
Main:
#Region Project Attributes
    #ApplicationLabel: aeon auto
    #VersionCode: 1
    #VersionName: aeon auto
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: portrait
    #CanInstallToExternalStorage: False
#End Region

#AdditionalJar: androidx.core
#AdditionalJar: androidx_car_app

#Region Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

#BridgeLogger: True

Sub Process_Globals
    Private xui As XUI
    Private notificationId As Int = 1
End Sub

Sub Globals
    Private btnSend As Button
    Private jo As JavaObject
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("layout")
    btnSend.Text = "Send to Android Auto"
    Log("Activity created")
End Sub

Sub Activity_Resume
    Log("Activity resumed")
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    Log("Activity paused")
End Sub

Sub btnSend_Click
    Log("btnSend clicked")
    CreateNotification("AEON", "This is a notification for Android Auto")
End Sub

Sub CreateNotification(title As String, text As String)
    Log("Creating notification")
    Dim ctxt As JavaObject
    ctxt.InitializeContext
 
    Dim builder As JavaObject
    builder.InitializeNewInstance("androidx.core.app.NotificationCompat$Builder", Array(ctxt, GetChannelId))
    builder.RunMethod("setContentTitle", Array(CharSequence(title)))
    builder.RunMethod("setContentText", Array(CharSequence(text)))
    builder.RunMethod("setSmallIcon", Array(GetResourceId("drawable", "icon")))
    Log("Builder initialized")
 
    Dim importance As Int = 3 ' NotificationManager.IMPORTANCE_DEFAULT
    builder.RunMethod("setPriority", Array(importance))
    Log("Priority set")
 
    ' Add CarExtender for Android Auto
    Dim carExtender As JavaObject
    carExtender.InitializeNewInstance("androidx.core.app.NotificationCompat$CarExtender", Null)
    ' Here you can configure other options like setColor or setLargeIcon if necessary
    builder = carExtender.RunMethod("extend", Array(builder))
    Log("CarExtender added")
 
    ' Add an action for Android Auto
    Try
        Dim intent As JavaObject
        intent.InitializeNewInstance("android.content.Intent", Null)
        intent.RunMethod("setClassName", Array(ctxt.RunMethod("getPackageName", Null), "com.fiveaces.aeonauto.main"))
        intent.RunMethod("setFlags", Array(268435456)) ' FLAG_ACTIVITY_NEW_TASK
     
        Dim pendingIntent As JavaObject
        Dim flags As Int = 67108864 ' FLAG_IMMUTABLE
        pendingIntent.InitializeStatic("android.app.PendingIntent")
        pendingIntent = pendingIntent.RunMethod("getActivity", Array(ctxt, 0, intent, flags))
        builder.RunMethod("setContentIntent", Array(pendingIntent))
        builder.RunMethod("addAction", Array(GetResourceId("drawable", "notification_icon"), CharSequence("Open App"), pendingIntent))
        Log("Action added")
    Catch
        Log(LastException.Message)
    End Try
 
    Dim nm As JavaObject = ctxt.RunMethod("getSystemService", Array("notification"))
    nm.RunMethod("notify", Array(notificationId, builder.RunMethod("build", Null)))
    Log("Notification sent")
End Sub

Sub GetResourceId(ResourceType As String, ResourceName As String) As Int
    Dim ctxt As JavaObject
    ctxt.InitializeContext
    Dim res As JavaObject = ctxt.RunMethod("getResources", Null)
    Return res.RunMethod("getIdentifier", Array(ResourceName, ResourceType, ctxt.RunMethod("getPackageName", Null)))
End Sub

Sub GetChannelId As String
    Dim channelId As String = "default_channel"
    Dim p As Phone
    If p.SdkVersion >= 26 Then
        Dim channel As JavaObject
        channel.InitializeNewInstance("android.app.NotificationChannel", Array(channelId, "Default Channel", 3))
        Dim ctxt As JavaObject
        ctxt.InitializeContext
        Dim nm As JavaObject = ctxt.RunMethod("getSystemService", Array("notification"))
        nm.RunMethod("createNotificationChannel", Array(channel))
    End If
    Return channelId
End Sub

Sub CharSequence(text As String) As Object
    Dim jo As JavaObject
    jo.InitializeStatic("anywheresoftware.b4a.BA")
    Return jo.RunMethod("ObjectToCharSequence", Array(text))
End Sub


Currently I'm trying to display an icon with a message with Jar libraries, not easy
 

Attachments

  • auto.zip
    23.8 KB · Views: 83
Last edited:
Upvote 0

Mr Blue Sky

Active Member
Licensed User
Longtime User
The result is exactly the same as mine.
As part of this project to integrate a B4A application with Android Auto, I am faced with a major constraint: the absence of libraries compatible with B4A facilitating this integration. To overcome this challenge, I propose the creation of a proxy application developed in Java or Kotlin. This app would act as an intermediary between our B4A app and Android Auto, receiving data and notifications from our B4A app to forward to Android Auto. Realizing this solution would require the expertise of developers specialized in Java or Kotlin, skills that I do not currently possess. This will involve sending from B4A a message of the type “MESSAGE as well as its icon”. ?
 
Last edited:
Upvote 0
Top