Google TV

Google TV Notifications: Best Practices

Android notifications communicate warnings and errors to users. They also communicate the status of background tasks. In a Google TV application, you should use notifications sparingly, so you don't interfere with the user's TV viewing. Toast and Dialog notifications are same on Google TV as mobile devices. Because Google TV does not have a status bar, notifications directed to the status bar will instead appear in the Google TV Notifications dialog.

Toast Notifications

Toast notifications are perfect for displaying notifications that don't need too much attention. For example, a Toast is a good way to tell the user that a download has completed. Notice, though, that a Toast has a subtle appearance and fades automatically, so the user may not notice it. You can control how long the Toast appears with the setDuration() method:

  • Short: Shows the Toast for a short period of time. For example, this code snippet displays a short duration Toast:
        Toast.makeText(this, "Short notification", Toast.LENGTH_SHORT).show();
    
  • Long: Shows the Toast for a longer period of time. Use this to allow the user more time to read the message. For example:
        Toast.makeText(this, "Long notification", Toast.LENGTH_LONG).show();
    
  • Custom: Uses a customized View to display a custom Toast notification. To learn how to do this, read the topic Creating Toast Notifications in the Android Developers Guide.

Dialog Notifications

A Dialog is an activity-related notification. Use a Dialog for notifications that need a response from the user, or for information related to an ongoing operation. For example, use a Dialog for a login prompt or for a progress bar. When the Dialog is displayed it gets focus and appears in front of all other objects in the current view. It also becomes the target for all user input.

Status Bar Notifications: Notification Dialog

Google TV does not have a status bar, so notifications that would show in the status bar of a mobile device will appear instead in the Google TV Notifications dialog. This dialog displays when the user clicks the status panel icon on the Launcher bar.

You use Notification dialog notifications for messages that should display until the user takes some action, but should otherwise remain in the background. An example of this type of notification is a message telling that user that new e-mail has arrived. A Notification dialog notification, like a Toast, does not interrupt the current activity, but like a Dialog it can directly accept a user response.

As a reminder to the user, the status panel icon for the Notification dialog displays a count of the number of unviewed notifications.

Mobile devices display ongoing notifications above event-driven notifications in the drag-down status panel. In Google TV, the notification types are not separated.

Ticker Text Notifications

On mobile devices, ticker text notifications appear in the status bar. A Google TV device displays them as a Toast message and also as a notification in the Notifications dialog.

Event-driven Notifications

When you need to notify the user about an event that requires a response, use an event-driven notification. For example, notifying the user of an incoming e-mail is an event-driven notification. In Google TV, users remove event-driven notifications by opening the Notifications dialog and clicking Clear. To display a notification that can't be dismissed, use an ongoing notification.

For example, this code snippet creates a Notification object that you can use later on to notify the user of an event:

// loads an icon from the app's icon resources
int mIcon=R.drawable.icon;

// Sets the ticker text to display in the notification
CharSequence mTickerText="You have new notification";

// Sets the notification's message title
CharSequence mContentTitle ="Title here";

// Sets the message's text
CharSequence mContentText ="Message here";

// Creates a new Intent that will be sent back to the current Activity 
Intent mNotificationIntent=new Intent(this,MyActivity.class);

// Creates a PendingIntent from the Intent.
PendingIntent mContentIntent=PendingIntent.getActivity(this,0,mNotificationIntent,0);

// Creates a Notification.Builder object from the ticker text, icon, title, message text, and pending intent
Notification.Builder mBuilder= new Notification.Builder(this)
                        .setTicker(mTickerText)
                        .setSmallIcon(mIcon)
                        .setContentTitle(mContentTitle)
                        .setContentText(mContentText)
                        .setContentIntent(mContentIntent);

// Gets the resulting Notification object
Notification mNotification = mBuilder.getNotification();

You can now send this Notification object to the NotificationManager object, which displays the notification. When the user clicks the notification, the Intent in the Notification object will re-activate the Activity that created the Notification object.

Ongoing Notifications

When you need to keep the user informed about an event during the entire event, use an ongoing notification. Examples of ongoing events are playing a song or installing an app. Ongoing notifications can't be dismissed by clicking Clear, so the user is more likely to see the notification while the event is in progress.

To create an ongoing notification, create a Notification.Builder object (as demonstrated in the previous section) and then call the setOngoing() method:

// Creates a Notification.Builder object
Notification.Builder mBuilder = new Notification.Builder(this);

// The rest of the settings for mBuilder go here

...

// Makes the Notification.Builder object an ongoing notification
mBuilder.setOngoing(true);

Ongoing events are often the result of tasks that hidden because they're running in the background. This is common for applications such as music players whose UIs don't need to be visible all the time.

Custom Notifications

You can customize the expanded notification that appears in the Notifications dialog using RemoteViews. This is described in the section "Creating a Custom Expanded View" in the Android Developers Guide.

For a Google TV application, when you create a custom expanded notification, don't use focusable elements such as Button, which are hard to trigger in the Google TV UI. Remember that TV system panel's outer frame is not easy to select with either the D-pad or the mouse.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.