From 1b3f51c4e10aa6f6e1f2e3a9ee3bcd9438a58bcb Mon Sep 17 00:00:00 2001 From: sreevanis Date: Wed, 6 Jan 2016 13:49:16 -0800 Subject: [PATCH] docs: Documented the new media constant used to determine if an app is currently selected by the user. Bug:23191905 Change-Id: I144a6ed115b48c4d834c64efbc6538779c7143c8 --- docs/html/training/auto/audio/index.jd | 28 ++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/docs/html/training/auto/audio/index.jd b/docs/html/training/auto/audio/index.jd index d183f119adefc..75974e44d1c77 100644 --- a/docs/html/training/auto/audio/index.jd +++ b/docs/html/training/auto/audio/index.jd @@ -210,6 +210,34 @@ href="https://www.youtube.com/watch?v=Q96Sw6v4ULg">

Note: The icon you provide should have transparency enabled, so the icon's background gets filled in with the app's primary color.

+

Determine if Your App is Connected

+

+It is possible to determine if your app is selected as the current media app.

+

+Android Auto broadcasts an intent with com.google.android.gms.car.media. +STATUS action when a user connects or disconnects from a media app. The broadcast intent is +scoped to the package name of the media app selected. You can register a broadcast receiver in your +app, preferably in your +MediaBrowserService implementation and listen for this intent +and adjust advertisements, metadata, and UI buttons in your app to operate safely in a vehicle.

+ +

The broadcasted intent has a String extra media_connection_status, that +contains either media_connected or media_disconnected string that represents + the current connection status.

+ +
+IntentFilter filter = new IntentFilter("com.google.android.gms.car.media.STATUS");
+BroadcastReceiver receiver = new BroadcastReceiver() {
+    ...
+    public void onReceive(Context context, Intent intent) {
+        String status = intent.getStringExtra("media_connection_status");
+        boolean isConnectedToCar = "media_connected".equals(status);
+        // adjust settings based on the connection status
+    }
+};
+registerReceiver(receiver, filter);
+
+

Build a Browser Service