Display toast on Android AUTO DHU

I am creating a media player for Android Auto, and I am struggling to create a simple toast message that appears on the car display head unit.

In my user actions, I have an action that should display a toast message on the Car interface, but when I implement a toast, it instead appears only on a handheld device / phone.

I searched the Internet high and low, and I can not find anything about how to display toasts on the car radio, although it is listed in the Auto Auto Android manual :: https://designguidelines.withgoogle.com/android-auto/android-auto/ app-ui.html # app-ui-drawer

can someone give me an example for getting visual feedback or toasts on the Android Auto Platform?

+5
source share
1 answer

You can not.

If you look at the following question: Developing a custom Android Auto application I shared a jar that allows you to use some of the non-standard Android Auto SDKs 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 classes and use CarToast as follows:

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

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

So, in order to correctly display the message, 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 that will only be displayed on the phone’s screen, and it will display a heads-up notification that will only appear on the car’s screen. Since no action is taken with it, nothing will happen if the use interacts with it with a notification.

If the phone is connected to the car, the phone screen will be turned off, so the Toast display will be ignored.

The problem with all this is that since the unofficial bank and SDK are not accessible to the public, you will not be able to publish the application on the PlayStore :( that, as they say, I was only trying to publish full applications, but an application that only displays a notification may pass through the filter.

0
source

Source: https://habr.com/ru/post/1273175/


All Articles