Integrating BlackBerry CPaaS with Android Auto: Secured Apps for Cars

Introduction

Over the past few months, you’ve probably heard a lot about BlackBerry’s unparalleled software being rolled out into the latest fleet of connected cars and autonomous vehicles. The ‘sickest whips’ at CES featured QNX embedded software systems in conceptual designs for the future, including the Aston Martin DB11 and Range Rover Supercharged. This month, a leader in software security for the automotive industry, BlackBerry CEO John Chen delivered a keynote address at the world-famous Detroit Auto Show. Clearly, BlackBerry is paving the way for the automotive future.

How You Can Build BlackBerry Secured Apps for Cars

Using the BlackBerry CPaaS (BBM Enterprise SDK), you can easily embed secure voice, video, and messaging into your application, and extend this functionality for use on Android Auto. This is an essential service for businesses with employees out in the field, who need safer access to their work applications while on the road. Fire departments, ambulances, police, delivery services, and any number of specialized vehicular workers can all benefit from their work applications being available on their car display, and having their communications secured by BlackBerry CPaaS. Thus, this article will teach you how to expand an existing sample application for use on Android Auto, where you can send and receive messages on your Android Auto display or desktop emulator.

Prerequisites:

There are only two prerequisites required to build and demo this highly secured Android Auto application:

First, build the ‘RichChat’ application that comes bundled with the free download of the BBM Enterprise SDK. This will serve as the starting point for this tutorial. Check out our BlackBerry Youtube channel for a quick getting started guide for RichChat.

To test the application, you need to have a car display with Android Auto, or simply install the Car Head Unit emulator on your desktop. For information on how to get the emulator set up for testing, check out the official Building Apps for Auto training documentation.

Configure the Manifest for Android Auto Support

Let’s get started! First, we need to tell the Android system that our app is now compatible with Android Auto displays. In the RichChat sample, we do this by declaring support for Android Auto messaging in our app manifest.

The above declaration refers to an additional XML file that we will add to our project. This file will tell the Android system what kind of service we would like to provide to Auto through our application. For this example, we would simply like to provide messaging and notification services to Android Auto.

Create the file automotive_app_desc.xml in the res/xml directory of your project with the following declaration:

<automotiveApp>
<uses name="notification"/>
</automotiveApp>

Next, we will declare our read and reply broadcast receivers in the app manifest. This will allow the Android Auto framework to recognize actions (intents objects) from our user. Things like playing back the audio for a text message and replying to a message with voice commands are handled through these receivers. For our sample, this can be done by including the following declarations in AndroidManifest.xml:

This initial configuration is standard for all Android Auto applications that support messaging. You can find more information about integrating messaging services for Android Auto on the official guide.

Expand the NotificationItem interface to include the conversation’s chatID

For simplicity, we will expand the NotificationItem Interface in BBMNotificationManager.java to include a method for getting the chatID directly from a chat NotificationItem. This can be done very simply by adding ~3 lines of code as follows:

In BBMNotificationManager.java add a declaration for the method getChatId() in the NotificationItem interface:

In ChatMessageNotificationItem.java, define the getChatId() method for the ChatMessageNotificationItem class (this class implements the NotificationItem interface) as follows:

@Override
public String getChatId() return mChatMessage.chatId;

Create the read and reply BroadcastReceivers

Create a new directory in your project for your Android Auto read and reply receivers (the directory path should look like …/richchat/auto). Next, create two new Java classes in this new directory, one for the read receiver, and one for the reply receiver:

Define the newly created Read Receiver:

This class defines the behavior that occurs when a user listens to a message in Android Auto. For our application, we will mark the message as ‘read’ using the ChatMessageRead API in the BBM Enterprise SDK. For more information, see the in-line comments in the code below.

Add the following code to the newly created MessageReadReceiver class:

Define the newly created Reply Receiver:

When the user replies to a message, Android Auto will send an intent back to the application and invoke the reply receiver to handle the action. For our application, we want to send the reply to the conversation it belongs to. This is done through the ChatMessageSend API in the BBM Enterprise SDK. For more information, see the in-line comments in the code below

Next, we’ll add two methods to create our intents for read and reply actions, to notify the android auto framework to communicate these actions back to the user when they occur.

Add the following two methods to the BBMNotificationManager:

// Creates an intent that will be triggered when a message is read.
private Intent getMessageReadIntent(String conversationId)
return new Intent().setAction(READ_ACTION)
.putExtra(CONVERSATION_ID, conversationId);
// Creates an Intent that will be triggered when a voice reply is received.
private Intent getMessageReplyIntent(String conversationId)
return new Intent().setAction(REPLY_ACTION)
.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES)
.setAction(REPLY_ACTION)
.putExtra(CONVERSATION_ID, conversationId);

Finally we will extend single message notifications that are triggered in the post() method of the BBMNotificationManager class to include support for Android Auto.

Add the following code to the post() method in BBMNotificationManager.java file:

And that’s it! Connect to your Android Auto display or emulator and try it out! You will now have notifications from the RichChat app read to you, and will be able to reply to messages with your voice.

RichChat on Android Auto in action:

For the sake of simplicity, this sample plays the most recent message received in the chat, and marks the entire conversation as read when that message is listened to. In a production environment, the app would play back the unread messages in order, and use the ChatMessage.messageId to mark the messages in the chat up to this message as ‘read’.

Disclaimer: SDKNews.com only syndicates the blog entries from various SDK blogs.
We are not the creator/author of these entries (posts). Product names, brand names
and company names mentioned on this site may be trademarks of their respective owners.