Displaying Toast on Android AUTO DHU
Asked Answered
L

1

7

I am building out a media player for Android Auto and struggling to make a simple Toast Message that appears on the Automotive Display Head Unit.

In my Custom Actions, I have an action that needs to display a toast message on the Car interface, but when I implement the toast it instead only shows on the handheld device/phone.

I have searched the internet high and low, and can not find anything about displaying toasts on the Car Head Unit, even though it is listed in the Android Auto Design guide:: https://designguidelines.withgoogle.com/android-auto/android-auto/app-ui.html#app-ui-drawer

could someone please point me to an example for giving visual feedback or toasts on the Android Auto Platform?

Lancelle answered 7/11, 2017 at 15:29 Comment(7)
for giving visual feedback you can use Notifications in it.Wan
understood, but we specifically want to display a toast as mentioned in the design guidelines. The problem with notifications is that we use toasts for this action on the handheld device, and don't want a notification.. if notifications are the only way, then we would need a way to determine if the user is currently attached to android auto to use logic to determine if we want a toast or a notification.Lancelle
in addition we don't want the user to have to interact t with the message.. we want it to just fade away after a short timeLancelle
Can it be related to the context that you are passing to the Toast?Aerostatic
I looked into that.. but we are passing the application context.. don't know how we would get the context of the headUnitLancelle
Can it be required this <uses name="toast" /> for using the feature like this for toastWan
where exactly would that go? the auto config seems to only allow media and notification as use namesLancelle
J
0

You cannot.

If you have a look at the following question: Develop an Android Auto custom app I have shared a jar which allows you to use some of the un-offical Android Auto SDK from there you can import this:

import com.google.android.apps.auto.sdk.CarToast;
import com.google.android.apps.auto.sdk.notification.CarNotificationExtender;

However even if you import the classes and use the CarToast like this:

CarToast.makeText(context,"SPEED CAMERA: " + text, Toast.LENGTH_LONG).show();

it will only display the toast on the phone screen not on the projected screen.

So to display a message correctly you will need to do something like this:

        CarToast.makeText(context,"SPEED CAMERA: " + text, Toast.LENGTH_LONG).show();

        CarNotificationExtender paramString2 = new CarNotificationExtender.Builder()
                .setTitle(title)
                .setSubtitle(text)
                .setShouldShowAsHeadsUp(true)
                .setActionIconResId(R.drawable.ic_danger_r)
                .setBackgroundColor(Color.WHITE)
                .setNightBackgroundColor(Color.DKGRAY)
                .setThumbnail(bmp)
                .build();

        NotificationCompat.Builder mynot = new NotificationCompat.Builder(context)
                .setContentTitle(title)
                .setContentText(text)
                .setLargeIcon(bmp)
                .setSmallIcon(R.drawable.ic_danger_r)
                .setColor(Color.GRAY)
                .extend(paramString2);


        mNotifyMgr.notify(1983,mynot.build());

This will show a toast which will only be visible on the phone screen and it will show a heads-up notification which will only be visible on the car's screen. Since there is no action attached to it, nothing will happen if the use interacts with it the notification.

If the phone is connected to the car the phone's screen will be turned off anyway so displaying Toast there will be ignored.

The problem with all this is that since it's an unofficial jar and the SDK is not available to the public you won't be able to publish the app on PlayStore :(, that being said I only tried to publish complete apps, but an app which just display notification might pass through the filter.

Junior answered 28/11, 2017 at 18:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.