Building Apps for Android Auto

37fbf83b7d45711e41e774e29fed710e?s=47 Arnav Gupta
September 16, 2016

Building Apps for Android Auto

37fbf83b7d45711e41e774e29fed710e?s=128

Arnav Gupta

September 16, 2016
Tweet

Transcript

  1. 2.

    . . . and soon on your toaster Well .

    . . Maybe quite not yet
  2. 4.

    Chrysler Jeep Hack Wired Magazine, July 2015 Charlie Miller and

    Chris Valasek Hacked a Chrysler Jeep and took control of steering and throttle. July, 2015 (Not using Android Auto)
  3. 5.
  4. 24.
  5. 25.

    Building Apps for Android Auto š Right now – only

    two types of Apps : š Audio Apps – Playback to car’s audio system š Messaging Apps – Text communication using voice commands š Android Auto v1 Does not have OBD/CAN bus data available in an API š Cannot control anything other than audio/video output for now
  6. 26.

    Building Apps for Android Auto š targetSdkVersion >= 21 š

    minSdkVersion >= 21 š Does NOT work with Lollipop phones š Needs Android v4 Support Library
  7. 32.

    Designing for Android Auto š Simple UI š Large buttons

    š Max depth = 6 š No ”BACK” button
  8. 33.

    Designing for Android Auto š Simple UI š Large buttons

    š Max depth = 6 š No ”BACK” button
  9. 34.

    Distraction Free Design š More options = more car accidents

    š Small buttons = more accidents š Low contrast = more accidents š Scrolling = more accidents š Video/Picture ads = u kidding bro ?
  10. 36.

    The navigation activity bar š Buttons – š Navigation š

    Communication š Home š Media š Car Dash š Single tap = default app, Double tap = optional apps
  11. 46.

    Testing Android Auto š Install the Android “Desktop Head Unit

    Simulator” in Android SDK š Install the “Android Auto App” on your Phone š Connect phone to PC
  12. 47.
  13. 48.

    Testing Android Auto š adb forward tcp:5277 tcp:5277 š cd

    <sdk>/extras/google/auto š ./desktop-head-unit
  14. 49.
  15. 52.

    Add your Service to Manifest <service android:name=".MyMusicService" android:exported="true"> <intent-filter> <action

    android:name="android.media.browse.MediaBrowserService" /> </intent-filter> </service>
  16. 53.

    Register a session for Playback @Override public void onCreate() {

    super.onCreate(); mSession = new MediaSession(this, "MyMusicService"); setSessionToken(mSession.getSessionToken()); mSession.setCallback(new MediaSessionCallback()); mSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS | MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS); }
  17. 59.

    Create Receivers and Service public class MessageReadReceiver extends BroadcastReceiver {

    … } public class MessageReplyReceiver extends BroadcastReceiver { … } public class MyMessagingService extends Service { … }
  18. 60.

    Register them <service android:name=".MyMessagingService"></service> <receiver android:name=".MessageReadReceiver"> <intent-filter> <action android:name="com.codingblocks.exampleandroidauto.ACTION_MESSAGE_READ" />

    </intent-filter> </receiver> <receiver android:name=".MessageReplyReceiver"> <intent-filter> <action android:name="com.codingblocks.exampleandroidauto.ACTION_MESSAGE_REPLY" /> </intent-filter> </receiver>
  19. 61.

    When message arrives @Override public void onReceive(Context context, Intent intent)

    { if (MyMessagingService.READ_ACTION.equals(intent.getAction())) { int conversationId = intent.getIntExtra(MyMessagingService.CONVERSATION_ID, -1); if (conversationId != -1) { Log.d(TAG, "Conversation " + conversationId + " was read"); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); notificationManager.cancel(conversationId); } } }
  20. 62.

    When user replies @Override public void onReceive(Context context, Intent intent)

    { if (MyMessagingService.REPLY_ACTION.equals(intent.getAction())) { int conversationId = intent.getIntExtra(MyMessagingService.CONVERSATION_ID, -1); CharSequence reply = getMessageText(intent); Log.d(TAG, "Got reply (" + reply + ") for ConversationId " + conversationId); } }
  21. 63.

    Get the user’s reply text from voice private CharSequence getMessageText(Intent

    intent) { Bundle remoteInput = RemoteInput.getResultsFromIntent(intent); if (remoteInput != null) { return remoteInput.getCharSequence(MyMessagingService.EXTRA_VOICE_REP LY); } return null; }
  22. 64.

    Create handler in Service class IncomingHandler extends Handler { @Override

    public void handleMessage(Message msg) { sendNotification(1, "This is a sample message", "John Doe", System.currentTimeMillis()); } }
  23. 65.

    Start read receiver from Service // A pending Intent for

    reads PendingIntent readPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), conversationId, createIntent(conversationId, READ_ACTION), PendingIntent.FLAG_UPDATE_CURRENT);
  24. 66.

    Start reply receiver from Service // Building a Pending Intent

    for the reply action to trigger PendingIntent replyIntent = PendingIntent.getBroadcast(getApplicationContext(), conversationId, createIntent(conversationId, REPLY_ACTION), PendingIntent.FLAG_UPDATE_CURRENT);
  25. 67.

    Create notifications on the home screen NotificationCompat.Builder builder = new

    NotificationCompat.Builder(getApplicationContext()) //.setSmallIcon(R.drawable.notification_icon) //.setLargeIcon(personBitmap) .setContentText(message) .setWhen(timestamp) .setContentTitle(participant) .setContentIntent(readPendingIntent) .extend(new CarExtender() .setUnreadConversation(unreadConvBuilder.build())); mNotificationManager.notify(conversationId, builder.build());
  26. 72.
  27. 78.

    Read More Android Auto resources from Google http://andriod.com/auto https://developer.android.com /training/auto

    https://github.com/googlesam ples/android-MessagingService https://github.com/googlesam ples/android- MediaBrowserService