View
16
Download
0
Category
Preview:
Citation preview
Android Auto App Development Getting Started
Shalini Saxena Honda Silicon Valley Lab
February 4th, 2015
Getting Started with Android Auto Android 5.0 or higher
Important links
Getting Started with Android Auto http://developer.android.com/training/auto/start/index.html
http://developer.android.com/training/auto/audio/index.html
http://developer.android.com/training/auto/messaging/index.html
Android Studio http://developer.android.com/sdk/index.html
Honda Developer Studio
https://developer.hondasvl.com
3
Auto applications
Android Auto supports two types of apps:
– Audio apps that allow users to browse and play music and spoken audio content in the car
– Messaging apps that receive incoming notifications, read messages aloud via text –to-speech and send replies via voice input in the car
4
Setup an Auto Project
Prerequisites
Recommended IDE – Android Studio
Create or update the app project to target Android 5.0
(API Level 21) Set Android manifest targetSdkVersion to 21 or higher
Install the support libraries
5
Setup an Auto Project – contd.
Declare Auto support
Auto XML configuration file, ex. res/xml/automotive_app_desc.xml
Add a manifest entry
6
audio app <automotiveApp>
<uses name="media" />
</automotiveApp>
messaging app <automotiveApp>
<uses name="notification" />
</automotiveApp>
<application> <meta-data android:name="com.google.android.gms.car.application"
android:resource="@xml/automotive_app_desc"/>
</application>
Audio Apps for Android Auto
7
1-2-3 of building Audio Apps for Auto
1. Configure App Manifest
Auto audio support
Declare a media browser service
2. Build a Browser Service
3. Enable Playback Control
8
1. Configure App Manifest
9
Declare Auto audio support – Auto XML configuration file : res/xml/automotive_app_desc.xml
Declare the media browser service
<application>
... <service android:name=".MyMediaBrowserService" android:exported="true"> <intent-filter> <action android:name= "android.media.browse.MediaBrowserService"/> </intent-filter> </service> ... <application>
2. Building a media browser service
Build a service that provides audio track listing information - extend MediaBrowserService.
Register a MediaSession object
Get the token for your app's MediaSession object, in order to control audio playback
Implement the MediaSession.Callback object to enable playback controls.
10
Media browser service
Important functions in the service implementation onCreate()
Declare MediaSession object and its callback object
Build content hierarchy with: onGetRoot()
returns information about the root node of the menu hierarchy
onLoadChildren()
Auto device client builds the top-level menu by calling this method with the root node object and getting it's children
Builds submenus by calling it with other child nodes
11
3. Enable playback controls
Register MediaSession object
Implement play commands using the MediaSession.Callback object
• onPlay()
• onPause()
• onPlayFromMediaId()
• onPlayFromSearch()
• onPause()
• onSkipToNext()
• onSkipToPrevious()
• onStop()
12
Messaging apps for Auto
13
Message notification
Messaging App – Read Message to User
14
1-2-3-4 of building messaging apps for Auto
1. Configure App Manifest
Auto messaging support
Define read and reply intent filters
2. Import Support Library for Messaging
3. Notify User of Messages
4. Handle User Actions
15
1. Configure App manifest file
Declare Auto notification support – Auto XML configuration file : res/xml/automotive_app_desc.xml
Define the read and reply intent filters
16
<application>
...
<receiver android:name=".MyMessageReadReceiver">
<intent-filter>
<action android:name="com.myapp.messagingservice.ACTION_MESSAGE_HEARD"/>
</intent-filter>
</receiver>
<receiver android:name=".MyMessageReplyReceiver">
<intent-filter>
<action android:name="com.myapp.messagingservice.ACTION_MESSAGE_REPLY"/>
</intent-filter>
</receiver>
...
<application>
2. Import Support Library for Messaging
Update the v4 Support Library Extras > Android Support Repository to version 9 or higher
Extras > Android Support Library to version 21.0.2 or higher.
Import the library into the Android Studio development project by adding this dependency to your build.gradle file:
17
dependencies {
...
compile 'com.android.support:support-v4:21.0.+'
}
3. Notify Auto User of Messages
Build and send a specific type of notification for display on Auto devices
Build message conversations
Associate Read and Reply Intents with each conversation
Send message as notification to Auto device
18
Build message conversations
NotificationCompat.CarExtender.UnreadConversation class
PendingIntent
Add messages to the UnreadConversation object
19
//Build a RemoteInput for receiving voice input in a Car Notification
RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY)
.setLabel(getApplicationContext()
.getString(R.string.notification_reply))
.build();
//Create an unread conversation object to organize a group of messages
//from a particular sender.
UnreadConversation.Builder unreadConvBuilder =
new UnreadConversation.Builder(participantName)
.setReadPendingIntent(msgHeardPendingIntent)
.setReplyAction(replyPendingIntent, remoteInput);
// Note: Add messages from oldest to newest to the UnreadConversation.Builder
for (Iterator<String> messages = conversation.getMessages().iterator();
messages.hasNext(); ) {
String message = messages.next();
unreadConvBuilder.addMessage(message);
Read and Reply Intents
PendingIntent for read and reply actions are associated with each unread conversation
20
Intent msgHeardIntent = new Intent()
.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES)
.setAction(com.myapp.messagingservice.ACTION_MESSAGE_HEARD)
.putExtra("conversation_id", conversationId);
PendingIntent msgHeardPendingIntent =
PendingIntent.getBroadcast(
getApplicationContext(),
conversationId,
msgHeardIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
Send Messages as notification to Auto
Add message to the NotificationCompat.CarExtender.UnreadConversation.Builder for this conversation, and update its timestamp:
Build notification
21
unreadConvBuilder.addMessage(messageString).setLatestTimestamp(currentTimestamp);
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(getApplicationContext())
.setSmallIcon(R.drawable.notification_icon)
.setLargeIcon(icon_bitmap)
.setContentText(messageString)
.setWhen(currentTimestamp)
.setContentTitle(participant_name)
.setContentIntent(msgHeardPendingIntent);
Send Messages as notification to Auto
Create and attach
NotificationCompat.CarExtender.UnreadConversation object to
NotificationCompat.CarExtender
Send notification using app’s NotificationManagerCompat
22
notificationBuilder.extend(new CarExtender()
.setUnreadConversation(unreadConvBuilder.build());
NotificationManagerCompat msgNotificationManager =
NotificationManagerCompat.from(context);
msgNotificationManager.notify(notificationId, notificationBuilder.build());
4.Handle Auto User Action - BroadcastReceiver
Configure your app to receive Intent objects that indicate
Auto user has read or replied to a message.
Read/Heard Action
Reply Action
When the user hears or replies to a message the Auto device sends a read/reply intent
App invokes the broadcast receiver class associated to it to handle that action
23
Testing the apps
• Using the Simulator
From the Extras install the Android Media Browser simulator on
the test device • Audio <sdk>/extras/google/simulators/media-browser-simulator.apk
• Messaging <sdk>/extras/google/simulators/messaging-simulator.apk
• Honda Developer Studio
Register to become a part of the HDS
24
Important links
Getting Started with Android Auto http://developer.android.com/training/auto/start/index.html
http://developer.android.com/training/auto/audio/index.html
http://developer.android.com/training/auto/messaging/index.html
Android Studio
http://developer.android.com/sdk/index.html
Honda Developer Studio
https://developer.hondasvl.com
25
Introduction to
John Moon Honda Silicon Valley Lab
February 4th, 2015
Honda Silicon Valley Lab & HDS
HSVL Mission: Open Innovation
Connected Vehicle Human Machine Interface
Apps/Contents Big Data
28
What is Honda Developer Studio?
• Open-innovation, collaborative workspace in Mountain View, CA
• Online portal – http://developer.hondasvl.com/
Benefits to Developers
• Latest platform information
• Access to test vehicles
• Access to Honda engineering team
• Be involved in the automotive community
Studio Visit
1. Register online and make an appointment
2. Meeting with engineering team to discuss your application
3. HDS loads your application for the test drive
4. HDS provide feedback and answer any questions
Input and Output
32
Telephony Buttons
Audio Controls
Microphone
Audio System
USB (to Phone)
Display
User Inputs Outputs
Load Your App on Our Environment
Developer’s APK
Take a Test Drive
http://developer.hondasvl.com
Thank You for your attention
Recommended