This page explains how to receive a notification on the SmartEyeglass. Notifications in the SmartExtensions framework are similar to standard Android Notifications. You can use them to notify users when they receive, for example, an SMS, email, or Facebook update.

The SmartExtensions framework provides a notifications service based on Android ContentProviders. Your application can use the service to inform users of new events or messages using the SmartEyeglass display.

The basics

To get started configuring notifications for SmartEyeglass display, set up a project using the HelloNotification sample; see more about creating SmartEyeglass projects in the How to create your first SmartEyeglass project tutorial.

The notification functionality is implemented at the level of the SmartExtensions API. As for any SmartEyeglass project, you must include the SmartExtensions libraries in your project. You must also update your AndroidManifest.xml file with Intent filters for the Notification API, as defined by the NotificationUtil class in the SmartExtensionUtils library. The manifest in the sample does this. See SmartEyeglass API overview for more details on updating your Android Manifest.

These classes in the HelloNotification sample project implement the SmartEyeglass handling of notifications:


Design a safe notification display

You can extend the ExtensionService class, as shown in the sample, to specify what information is displayed in the notification. For SmartEyeglass applications, the user status (moving or still) and screen status (on or off) will determine how notifications are displayed.

The sudden display of text tends to distract the user, especially when the screen is off. Whenever the user is in motion, it is recommended that you avoid displaying text on the SmartEyeglass; as in this case, an icon should be sufficient. When the user is still, it is safe to provide more details.

When screen is off, display style depends on user’s motion.

When screen is off, display style depends on user’s motion.

When the screen is off and the user is in motion, a notification shows only the 52×52 pixel application icon for the sending application. When the user is at rest, the user name is added to the display.

When screen is on, the display includes message information.

When screen is on, the display includes message information.

When the screen is on, information about the sending application is displayed along with additional message details, including a 52×52 pixel icon and 24-pixel text.

In all cases, the notification flashes three times in two seconds, and then remains on the screen for one second. To make sure users know which application sent the notification, we recommend that you use a clear, recognizable icon.

Configure notifications

To support notifications in your SmartEyeglass app, you must identify notification sources that you are interested in, and define which notification information you want to display in particular circumstances.

Add a notification source

A notification source is a ContentValues object in your extension’s registration information that identifies where notifications are coming from. To receive notifications, you must add at least one source. It is possible to have notifications come from multiple sources, such as from multiple RSS feeds. If you plan to support multiple sources, you will need to create a ContentValue list of different source configurations and return all of them as an array. For example:

public ContentValues[] getSourceRegistrationConfigurations() {
    List bulkValues = new ArrayList();
    bulkValues.add(getSourceRegistrationConfiguration (SampleExtensionService.EXTENSION_SPECIFIC_ID));
    return bulkValues.toArray(new ContentValues[bulkValues.size()]);

Configure each notification source

When you have registered your extension to support the Notification API, the host app will call getSourceRegistrationConfiguration()for your extension in order to get the specific configuration information for notification source. You will need to override this method to define the configuration values you want for your notification source such as icon, source name, whether it supports text to speech, and so on. For more information about which values are supported, see the Notification.SourceColumns constants in the API references.

This is the configuration method defined for the sample:

* Get source configuration for this extension
* 	@param Your extension’s unique ID
* 	@return The source configuration
public ContentValues getSourceRegistrationConfiguration (String extensionSpecificId) {
    ContentValues sourceValues = null;

    String iconSource1 = ExtensionUtils.getUriString(mContext, R.drawable.icn_30x30_message_notification);
    String textToSpeech = mContext.getString(R.string.text_to_speech);
    sourceValues = new ContentValues();

    sourceValues.put(Notification.SourceColumns.ENABLED, true);
    sourceValues.put(Notification.SourceColumns.ICON_URI_1, iconSource1);
    sourceValues.put(Notification.SourceColumns.UPDATE_TIME, System.currentTimeMillis());
    sourceValues.put(Notification.SourceColumns.NAME, mContext.getString(R.string.source_name));
    sourceValues.put(Notification.SourceColumns.EXTENSION_SPECIFIC_ID, extensionSpecificId);
    sourceValues.put(Notification.SourceColumns.PACKAGE_NAME, mContext.getPackageName());
    sourceValues.put(Notification.SourceColumns.TEXT_TO_SPEECH, textToSpeech);

  // Menu actions and icons
    sourceValues.put(Notification.SourceColumns.ACTION_1, mContext.getString(R.string.action_event_1));
    sourceValues.put(Notification.SourceColumns.ACTION_2, mContext.getString(R.string.action_event_2));
    sourceValues.put(Notification.SourceColumns.ACTION_3, mContext.getString(R.string.action_event_3));
    sourceValues.put(Notification.SourceColumns.ACTION_ICON_1, ExtensionUtils.getUriString(mContext, R.drawable.actions_1));
    sourceValues.put(Notification.SourceColumns.ACTION_ICON_2, ExtensionUtils.getUriString(mContext, R.drawable.actions_2));
    sourceValues.put(Notification.SourceColumns.ACTION_ICON_3, ExtensionUtils.getUriString(mContext, R.drawable.actions_3));

    return sourceValues;

Display a notification

To display the notification, add it to the notification database by inserting it into the notification ContentResolver. When it receives a notification that is in the database, the host application pushes it out to the accessory to be displayed.

When you add a notification, you can specify the title (DISPLAY_NAME) and message (MESSAGE). These values are added to a ContentValues object and inserted into the database. Values for PERSONAL, PUBLISHED_TIME, and SOURCE_ID are also required. For details on the values supported see the API references for Notification.EventColumns.

String name = “Earth”;
String message = “Hello World!”;
long time = System.currentTimeMillis();
long sourceId = NotificationUtil.getSourceId(this, EXTENSION_SPECIFIC_ID);
. . .
ContentValues eventValues = new ContentValues();
eventValues.put(Notification.EventColumns.DISPLAY_NAME, name);
eventValues.put(Notification.EventColumns.MESSAGE, message);
eventValues.put(Notification.EventColumns.PERSONAL, 1);
eventValues.put(Notification.EventColumns.PUBLISHED_TIME, time);
eventValues.put(Notification.EventColumns.SOURCE_ID, sourceId);
. . .
getContentResolver().insert(Notification.Event.URI, eventValues);
. . .

Add an image to your notification

Typically, a notification displays the sending user’s profile image. If you want to do this, add a PROFILE_IMAGE_URI as one of your content values. For example:

String profileImage = ExtensionUtils.getUriString(this, R.drawable.widget_default_userpic_bg);
eventValues.put(Notification.EventColumns.PROFILE_IMAGE_URI, profileImage);

Handle menu actions

You can define a menu to be shown in the notification view when the user drills down into the notification details.

Menu for notification view, defined by HelloNotification sample code.

Menu for notification view, defined by HelloNotification sample code.

To do this, override the onViewEvent() method and add your action handling code:

protected void onViewEvent(Intent intent) {
    String action = intent.getStringExtra(Notification.Intents.EXTRA_ACTION);
    . . .
    if (Notification.SourceColumns.ACTION_1.equals(action)) {
        Toast.makeText(this, "Action 1", Toast.LENGTH_LONG).show();
    else if (Notification.SourceColumns.ACTION_2.equals(action)) {
        Toast.makeText(this, "Action 2", Toast.LENGTH_LONG).show();
    else if (Notification.SourceColumns.ACTION_3.equals(action)) {
        Toast.makeText(this, "Action 3", Toast.LENGTH_LONG).show();

Learn from the code example

For the full code example showing how to use notifications, see the HelloNotification sample project in the /samples folder of the SmartEyeglass SDK.

Comments 0

Sort by:

Showing 0 of 0 comments. Show all comments