README.txt
1 Android Automobile sample
2 =========================
3
4
5 Integration points
6 ------------------
7
8 MusicService.java is the main entry point to the integration. It needs to:
9
10 - extend android.service.media.MediaBrowserService, implementing the media browsing related methods onGetRoot and onLoadChildren;
11 - start a new MediaSession and notify it's parent of the session's token (super.setSessionToken());
12 - set a callback on the MediaSession. The callback will receive all the user's actions, like play, pause, etc;
13 - handle all the actual music playing using any method your app prefers (for example, the Android MediaPlayer class)
14 - update info about the playing item and the playing queue using MediaSession (setMetadata, setPlaybackState, setQueue, setQueueTitle, etc)
15 - handle AudioManager focus change events and react appropriately (eg, pause when audio focus is lost)
16 - declare a meta-data tag in AndroidManifest.xml linking to a xml resource
17 with a <automotiveApp> root element. For a media app, this must include
18 an <uses name="media"/> element as a child.
19 For example, in AndroidManifest.xml:
20 <meta-data android:name="com.google.android.gms.car.application"
21 android:resource="@xml/automotive_app_desc"/>
22 And in res/values/automotive_app_desc.xml:
23 <?xml version="1.0" encoding="utf-8"?>
24 <automotiveApp>
25 <uses name="media"/>
26 </automotiveApp>
27
28 - be declared in AndroidManifest as an intent receiver for the action android.media.browse.MediaBrowserService:
29
30 <!-- Implement a service -->
31 <service
32 android:name=".service.MusicService"
33 android:exported="true"
34 >
35 <intent-filter>
36 <action android:name="android.media.browse.MediaBrowserService" />
37 </intent-filter>
38 </service>
39
40
41 Optionally, you can listen to special intents that notify your app when a car is connected/disconnected. This may be useful if your app has special requirements when running on a car - for example, different media or ads. See CarPlugReceiver for more information.
42
43
44 Customization
45 -------------
46
47 The car media app has only a few customization opportunities. You may:
48
49 - Set the background color by using Android L primary color:
50 <style name="AppTheme" parent="android:Theme.Material">
51 <item name="android:colorPrimary">#ff0000</item>
52 </style>
53
54 - Add custom actions in the state passed to setPlaybackState(state)
55
56 - Handle custom actions in the MediaSession.Callback.onCustomAction
57
58
59
60 Known issues:
61 -------------
62
63 - Sample: Resuming after pause makes the "Skip to previous" button disappear
64
65 - Sample: playFromSearch creates a queue with search results, but then skip to next/previous don't work correctly because the queue is recreated without the search criteria
66
67 - Emulator: running menu->search twice throws an exception.
68
69 - Emulator: Under some circumstances, stop or onDestroy may never get called on MusicService and the MediaPlayer keeps locking some resources. Then, mediaPlayer.setDataSource on a new MediaPlayer object halts (probably) due to a deadlock. The workaround is to reboot the device.
70
71