diff --git a/docs/html/training/auto/audio/index.jd b/docs/html/training/auto/audio/index.jd index aa20e3a29f9b2..3a1b1e8834941 100644 --- a/docs/html/training/auto/audio/index.jd +++ b/docs/html/training/auto/audio/index.jd @@ -21,6 +21,7 @@ page.image=auto/images/assets/icons/media_app_playback.png
  • Configure Your Manifest
  • Determine if Your App is Connected
  • Handle Alarms
  • +
  • Handle Media Advertisements
  • Build a Browser Service
  • Implement Play Controls
  • Support Voice Actions
  • @@ -261,7 +262,7 @@ following things: @@ -279,6 +280,33 @@ The following code snippet checks whether an app is running in car mode: } +

    Handle Media Advertisements

    +

    By default, Android Auto displays a notification when +the media metadata changes during an audio playback session. When a media +app switches from playing music to running an advertisement, it is distracting +(and unnecessary) to display a notification to the user. To prevent Android Auto +from displaying a notification in this case, you must set the media metadata +key {@code android.media.metadata.ADVERTISEMENT} to 1, as shown in the code +snippet below: + +

    +
    +@Override
    +public static final String EXTRA_METADATA_ADVERTISEMENT =
    +            "android.media.metadata.ADVERTISEMENT";
    +
    +public void onPlayFromMediaId(String mediaId, Bundle extras) {
    +    MediaMetadata.Builder builder = new MediaMetadata.Builder();
    +    // ...
    +    if (isAd(mediaId)) {
    +        builder.putLong(EXTRA_METADATA_ADVERTISEMENT, 1);
    +    }
    +    // ...
    +    mediaSession.setMetadata(builder.build());
    +}
    +
    +
    +

    Build a Browser Service

    Auto devices interact with your app by contacting its implementation of a