erik
erik

Reputation: 4958

Displaying Toast on Android AUTO DHU

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?

Upvotes: 7

Views: 2386

Answers (2)

Paras Palli
Paras Palli

Reputation: 201

CarToast.makeText(carContext, "Location Permission is required", CarToast.LENGTH_LONG).show()

Upvotes: 0

Emil Borconi
Emil Borconi

Reputation: 3467

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.

Upvotes: 0

Related Questions