[Android Software Development] Geeks Empire:
Android Auto [Data Transferring]

​

NOTE: Currently Only Media Player & Short Messaging App allowed on Google Play Store for Android Auto Distribution.

But Soon there will be another category for more Hands-Free App on Android Auto.

Android Auto is now available on these cars

Hyundai Sonata (May 2015) Take it to Service Center & Ask for Upgrade to Android Auto

Skoda Fabia (June 2015)

Skoda Superb (June 2015)

Skoda Octavia (June 2015)

Honda Accord (August 2015)

VW Golf/GTI (September 2015)

Chevrolet Cruze (2016)

& Enabled Hardware are

GPS and high-quality GPS antennas

Steering-wheel controls

Sound system

Directional speakers

Directional microphones

Wheel speed

Compass

Mobile antennas

### Let Start Coding ###

. from Bottom to Top

First you need to Add XML file as meta-data for AndroidManifest to declare app as AndroidAuto Enabled app for system.

Under the .../res/ create xml folder. inside xml folder create xml resource file: automotive_app_desc.xml and Paste this

<?xml version="1.0" encoding="utf-8"?>
<automotiveApp>
<uses name="[B]notification[/B]"/>
<!-- [I]notification attribute shows your app is messaging app that only create androidAuto compatible notification[/I] -->
</automotiveApp>

then you need to link this file into manifest under <application />

<meta-data
android:name="com.google.android.gms.car.application"
android:resource="@xml/automotive_app_desc" /

>

After Installing App, It will notify Android Auto System.

There is 2 parts important for AndroidAuto Notification When TTS read content & when want to Reply Or send reply.

So to handle these parts we should define two BroadcastReceiver in manifest & creating classes.

<receiver android:name=".[B]MessageReadReceiver[/B]">
<intent-filter>
<action android:name="net.test.cartest.[B]ACTION_MESSAGE_READ[/B]"/>
</intent-filter>
</receiver>

<receiver android:name=".[B]ReplyReceiver[/B]" >
<intent-filter>
<action android:name="net.test.cartest.[B]ACTION_MESSAGE_REPLY[/B]" />
</intent-filter>
</receiver>

Then Create Classes & setup both of them as extends BroadcastReceiver.

Inside Activity class we need to create Android-Auto Compatible Notification.

For Messaging App It should be after users receive new message. I used it for Translator App > geTranslate. It means Notification will show translated text on Car Monitor Read result & use Reply action to reuse translator. However Translator App is not allowed for Android Auto.

Before creating notification we should define Intent Action to invoke BroadcastReceiver previously defined.

private Intent getMessageReadIntent(int conversationId) {
return new Intent().setAction(READ_ACTION).putExtra(CONVERSATION_ID, id); //[FONT=Impact](Check Source Code)[/FONT]
}
//Conversation ID must be unique.
private Intent getMessageReplyIntent(int conversationId) {
return new Intent().setAction(REPLY_ACTION).putExtra(CONVERSATION_ID, conversationId); //[FONT=Impact](Check Source Code)[/FONT]
}

Creating Notification itself is similar to phone notification But we need to extend it for Cars. to do this we need another component UnreadConversation.Builder

//This element will handle new how create new notifications
UnreadConversation.Builder unreadConversationBuilder = new UnreadConversation.Builder(sender)
.setLatestTimestamp(timestamp)
.setReadPendingIntent(readPendingIntent)
.setReplyAction(replyIntent, remoteInput);

unreadConversationBuilder.addMessage(message);

Then we should use it for CarExtender()

new CarExtender().setUnreadConversation(unreadConversationBuilder.build();

Here is Complete Function to define and create Android Auto Compatible Notification

private void sendNotificationToCar(int conversationId, String sender, String message, long timestamp) {
PendingIntent readPendingIntent = PendingIntent.getBroadcast(
getApplicationContext(),
conversationId,
getMessageReadIntent(conversationId),
PendingIntent.FLAG_UPDATE_CURRENT);

RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY)
.setLabel("Remote Inpute").build();

PendingIntent replyIntent = PendingIntent.getBroadcast(
getApplicationContext(),
conversationId,
getMessageReplyIntent(conversationId),
PendingIntent.FLAG_UPDATE_CURRENT);

UnreadConversation.Builder unreadConversationBuilder = new UnreadConversation.Builder(sender)
.setLatestTimestamp(timestamp)
.setReadPendingIntent(readPendingIntent)
.setReplyAction(replyIntent, remoteInput);

unreadConversationBuilder.addMessage(message);

NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext())
.setSmallIcon(R.drawable.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.ic_launcher))
.setContentText(message)
.setWhen(timestamp)
.setContentTitle(sender)
.setContentIntent(readPendingIntent)
.extend(new CarExtender().setUnreadConversation(unreadConversationBuilder.build()))
.setColor(Color.RED);

NotificationManagerCompat.from(this).notify(conversationId, builder.build());
}

Now you should handle Receivers. inside MessageReadReceiver you need to define actions to occur after TTS Engine read the content of notification & inside ReplyReceiver How reply actions work, in geTranslate I setup ReplayReceiver to invoke translator to translate what user spoke through car microphone.

public class [B]ReplyReceiver [/B]extends BroadcastReceiver { //[FONT=Impact](Check Source Code)[/FONT]
@Override
public void onReceive(Context context, Intent intent) {
if (MainActivity.REPLY_ACTION.equals(intent.getAction())) {
CharSequence reply = getMessageText(intent);

//Do What you want...
}
}

private CharSequence getMessageText(Intent intent) {
Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
if (remoteInput != null) {
return remoteInput.getCharSequence(MainActivity.EXTRA_VOICE_REPLY);
}
return null;
}
}

Up to Here you did what necessary for your app to support Android Auto. If you have access to real AndroidAuto Powered Vehicle Just Install you app and connect it to car & test your application.

But If you don't have access to androidAuto car you need to use simulator.

Install [COLOR=RoyalBlue][URL="http://xdaforums.com/attachment.php?attachmentid=3444494&stc=1&d=1439998349"][B]CarNotification.APK[/B][/URL][/COLOR]

Install [B][URL="http://xdaforums.com/attachment.php?attachmentid=3444491&stc=1&d=1439998135"]Simulator APK[/URL][/B] & Go to Setting > Notification Access > Enable Simulator

HOW TO Test Sample

[B]Open [/B]CarTest [B]Click [/B]on Text Then Click [B]Home [/B]& [B]Run Simulator [/B]> Wait [B]15Seconds [/B]to See Notification

Don't forget to Hit Thanks

​