Android设计和开发系列第一篇:Notifications通知(Design)

Design

Notifications

The notification system allows users to keep informed about relevant and timely events in your app, such as new chat messages from a friend or a calendar event. Think of notifications as a news channel that alerts the user to important events as they happen or a log that chronicles events while the user is not paying attention—and one that is synced as appropriate across all their Android devices.

//通知,系统允许用户在你的APP里随时了解紧密相关的及时性的事件,例如来自一个朋友的最新的聊天信息或者日程事件。把通知当作是一个新闻频道,当一个重要的事件发生它会提醒用户,或者一个日志记载的事件在用户不关心的情况下,其中会适当的同步到用户的所有Android设备。

New in Android 5.0

In Android 5.0, notifications receive important updates: structurally, visually, and functionally:

//在Android5.0里,notifications带来了新的特性:结构化,视觉化,功能化:

  • Notifications have undergone visual changes consistent with the new material design theme.//通知带来了与material设计主题一样的视觉变化
  • Notifications are now available on the device lock screen, while sensitive content can still be hidden behind it.//现在通知在设备锁屏时可用了,而敏感的内容依然可以隐藏起来
  • High-priority notifications received while the device is in use now use a new format called heads-up notifications.//在可用的设备上带来了高优先级的通知,我们用一个新的称呼叫做抬头通知
  • Cloud-synced notifications: Dismissing a notification on one of your Android devices dismisses it on the others, as well.//云同步通知:当在你的一个设备取消一个通知时,其他所有设备也一样会被取消。

Note: Notification design in this version of Android is a significant departure from that of previous versions. For information about notification design in previous versions, see Notifications in Android 4.4 and lower.

//注意:在这个版本的通知设计是基于之前版本的显著提升。需要查看以前版本的通知设计,链接至 Notifications in Android 4.4 and lower.

Anatomy of a Notification //解析通知


This section goes over basic parts of a notification and how they can appear on different types of devices.

//本节介绍通知的基本组成部分和通知如何在不同设备上的呈现

Base layout //基础布局

At a minimum, all notifications consist of a base layout, including://最mini的通知,由基本布局组成,包括:

  • The notification's icon. The icon symbolizes the originating app. It may also potentially indicate notification type if the app generates more than one type.//通知的图标,这个图标代表原始的app,它可以暗示通知类型如果app会产生多种类型的话。
  • A notification title and additional text.//通知的标题和内容
  • timestamp.//时间戳

Notifications created with Notification.Builder for previous platform versions look and work the same in Android 5.0, with only minor stylistic changes that the system handles for you. For more information about notifications on previous versions of Android, see Notifications in Android 4.4 and lower.

//通知由Notification.Builder生成,在之前的版本可以参照Android5.0工作原理都是一样的,只有轻微的风格上的变化系统将会帮你处理。关于旧版本通知的更多信息,请看Notifications in Android 4.4 and lower.


Base layout of a handheld notification (left) and the same notification on Wear (right), with a user photo and a notification icon

//基础布局在手机的通知(左)和同样的通知在wear(右)上,同时有一个用户图片和通知图标。

Expanded layouts //扩展布局

You can choose how much detail your app's notifications should provide. They can show the first few lines of a message or show a larger image preview. The additional information provides the user with more context, and—in some cases—may allow the user to read a message in its entirety. The user can pinch-zoom or perform a single-finger glide to toggle between compact and expanded layouts. For single-event notifications, Android provides three expanded layout templates (text, inbox, and image) for you to use in your application. The following images show you how single-event notifications look on handhelds (left) and wearables (right).

//你可以选择你app通知提供详细。他们可以显示一条消息的前几行或者一个大的图片。附加信息为用户提供更多内容,在某些情况下允许用户在完整模式下阅读全部消息。用户可以捏合缩放或者通过一个手指滑动来切换普通布局和扩展布局。对于单事件通知,Android提供三种扩展布局模板(text,inbox,image)在app里使用。下面的图片展示了单事件通知在手机和手表上的样子。

  

Actions //动作

Android supports optional actions that are displayed at the bottom of the notification. With actions, users can handle the most common tasks for a particular notification from within the notification shade without having to open the originating application. This speeds up interaction and, in conjunction with swipe-to-dismiss, helps users focus on notifications that matter to them.

//Android支持可选的操作在通知的底部显示。通过action用户可以在特定的通知中处理常见的任务,在通知中即可操作而不需要进入app程序里面。它将提高交互性,联合滑动消失帮助用户聚焦匹配到的通知。


Be judicious with how many actions you include with a notification. The more actions you include, the more cognitive complexity you create. Limit yourself to the smallest number of actions possible by only including the most imminently important and meaningful actions.

//在通知中适当的使用action。更多的动作你可以包含它,更复杂的感知需要自己去创建。尽量限制使用action最小的数量,只包括最重要和最有意义的action。

Good candidates for actions on notifications are actions that: //在通知中最合理的动作:

  • Are essential, frequent, and typical for the content type you're displaying //必须的,频繁的,典型的显示内容类型
  • Allow the user to accomplish tasks quickly //帮组用户更快的完成任务

Avoid actions that are: //避免的动作:

  • Ambiguous //不明确的
  • The same as the default action of the notification (such as "Read" or "Open") //和action默认动作一样

You can specify a maximum of three actions, each consisting of an action icon and name. Adding actions to a simple base layout makes the notification expandable, even if the notification doesn't have an expanded layout. Since actions are only shown for expanded notifications and are otherwise hidden, make sure that any action a user can invoke from a notification is available from within the associated application, as well.

//你可以最多使用三个action,需要由一个动作图标和名字。通过在一个基本布局添加action来使通知具有扩展性,即使通知不具备扩展布局。由于action只展示在展开的通知,其他的将会隐藏,确保任何一个动作都可以在关联的app内部调用。

Heads-up Notification //抬头通知



Example of a heads-up notification (incoming phone call, high priority) appearing on top of an immersive app

When a high-priority notification arrives (see right), it is presented to users for a short period of time with an expanded layout exposing possible actions.

//抬头通知(来电,高权限)将出现在沉侵式app中的顶部,当一个高权限的通知到达时,将会出现在用户一个很短的时间内展开布局露出可能的actions.

After this period of time, the notification retreats to the notification shade. If a notification's priority is flagged as High, Max, or full-screen, it gets a heads-up notification.

//在很短的时间,这个通知将会撤出视线。如果通知权限的标志是High,Max,或者全屏,将会得到一个抬头通知。

Good examples of heads-up notifications //抬头通知比较好的案例

  • Incoming phone call when using a device //使用设备的时候来电
  • Alarm when using a device //使用设备的时候闹钟响了
  • New SMS message //新的消息
  • Low battery //电量过低

Guidelines //指南


Make it personal //个性化

For notifications of items sent by another person (such as a message or status update), include that person's image usingsetLargeIcon(). Also attach information about the person to the notification's metadata (see EXTRA_PEOPLE).

//当另一个人发送通知(例如一则消息或者状态更新),包括发送人的图像可以用setLargeIcon();也可以附加人的信息到通知的元数据。

Your notification's main icon is still shown, so the user can associate it with the icon visible in the status bar.

//你通知的主图标依然会显示,用户可以控制这个图标的可见性在状态栏上。


Notification that shows the person who triggered it and the content they sent.

//通知将会显示触发通知的人和发送的内容。

When the user touches the body of a notification (outside of the action buttons), open your app to the place where the user can view and act upon the data referenced in the notification. In most cases, this will be the detailed view of a single data item such as a message, but it might also be a summary view if the notification is stacked. If your app takes the user anywhere below your app's top level, insert navigation into your app's back stack so that the user can press the system back button to return to the top level. For more information, see Navigation into Your App via Home Screen Widgets and Notifications in the Navigation design pattern.

//当用户触摸在通知的主体(在action按钮之外),将会在用户看到的通知数据引用打开app。更多的情况下,将会展示单数据元素的详细视图,但它也会展示一个简略视图如果通知堆叠。如果你的app带你的用户到任何地方在app顶层以下,导航至app的回退栈,用户可以按下系统的返回按钮返回到app顶层。更多的信息,在桌面的widget和通知导航可以查看Navigation章节。

Correctly set and manage notification priority //正确得设置和管理通知权限

Android supports a priority flag for notifications. This flag allows you to influence where your notification appears, relative to other notifications, and helps ensure that users always see their most important notifications first. You can choose from the following priority levels when posting a notification:

//android中的通知支持权限标志。这个标志将影响通知在哪里出现,相对于其他通知,帮助确保用户始终可以看见最重要当然通知。当发送通知的时候你可以自己选择权限。

Priority

Use

MAX

Use for critical and urgent notifications that alert the user to a condition that is time-critical or needs to be resolved before they can continue with a particular task.//用于关键的紧急的通知,提醒用户这是急需处理才可以继续特定任务。

HIGH

Use primarily for important communication, such as message or chat events with content that is particularly interesting for the user. High-priority notifications trigger the heads-up notification display.

DEFAULT

Use for all notifications that don't fall into any of the other priorities described here.

LOW

Use for notifications that you want the user to be informed about, but that are less urgent. Low-priority notifications tend to show up at the bottom of the list, which makes them a good choice for things like public or undirected social updates: The user has asked to be notified about them, but these notifications should never take precedence over urgent or direct communication.

MIN

Use for contextual or background information such as weather information or contextual location information. Minimum-priority notifications do not appear in the status bar. The user discovers them on expanding the notification shade.

How to choose an appropriate priority //如何选择适当的权限

DEFAULTHIGH, and MAX are interruptive priority levels, and risk interrupting the user in mid-activity. To avoid annoying your app's users, reserve interruptive priority levels for notifications that:

  • Involve another person
  • Are time-sensitive
  • Might immediately change the user's behavior in the real world

Notifications set to LOW and MIN can still be valuable for the user: Many, if not most, notifications just don't need to command the user's immediate attention, or vibrate the user's wrist, yet contain information that the user will find valuable when they choose to look for notifications. Criteria for LOW and MIN priority notifications include:

  • Don't involve other people
  • Aren't time sensitive
  • Contain content the user might be interested in but could choose to browse at their leisure

If your notification falls into one of the predefined categories (see below), assign it accordingly. Aspects of the system UI such as the notification shade (or any other notification listener) may use this information to make ranking and filtering decisions.

CATEGORY_CALL

Incoming call (voice or video) or similar synchronous communication request

CATEGORY_MESSAGE

Incoming direct message (SMS, instant message, etc.)

CATEGORY_EMAIL

Asynchronous bulk message (email)

CATEGORY_EVENT

Calendar event

CATEGORY_PROMO

Promotion or advertisement

CATEGORY_ALARM

Alarm or timer

CATEGORY_PROGRESS

Progress of a long-running background operation

CATEGORY_SOCIAL

Social network or sharing update

CATEGORY_ERROR

Error in background operation or authentication status

CATEGORY_TRANSPORT

Media transport control for playback

CATEGORY_SYSTEM

System or device status update. Reserved for system use.

CATEGORY_SERVICE

Indication of running background service

CATEGORY_RECOMMENDATION

A specific, timely recommendation for a single thing. For example, a news app might want to recommend a news story it believes the user will want to read next.

CATEGORY_STATUS

Ongoing information about device or contextual status

Summarize your notifications //简化您的通知

If a notification of a certain type is already pending when your app tries to send a new notification of the same type, combine them into a single summary notification for the app. Do not create a new object.

A summary notification builds a summary description and allows the user to understand how many notifications of a particular kind are pending.

Don't

Do

You can provide more detail about the individual notifications that make up a summary by using the expanded digest layout. This approach allows users to gain a better sense of which notifications are pending and if they are interesting enough to read in detail within the associated app.

 

Make notifications optional //让通知可选

Users should always be in control of notifications. Allow the user to disable your app's nSince actions are only shown for expanded notifications and are otherwise hidden, make sure that any action a user can invoke from a notification is available from within the associated application, as well.otifications or change their alert properties, such as alert sound and whether to use vibration, by adding a notification settings item to your application settings.

Use distinct icons //使用清晰的图标

By glancing at the notification area, the user should be able to discern what kinds of notifications are currently pending.

Do

Look at the notification icons Android apps already provide and create notification icons for your app that are sufficiently distinct in appearance.

Do

Use the proper notification icon style for small icons, and the Material Light action bar icon stylefor your action icons.

Do

Keep your icons visually simple, avoiding excessive detail that is hard to discern.

Don't

Place any additional alpha (dimming or fading) into your small icons and action icons; they can have anti-aliased edges, but because Android uses these icons as masks (that is, only the alpha channel is used), the image should generally be drawn at full opacity.

Don't

Use color to distinguish your app from others. Notification icons should only be a white-on-transparent background image.

Pulse the notification LED appropriately //适当得使用通知LED灯

Many Android devices contain a notification LED, which is used to keep the user informed about events while the screen is off. Notifications with a priority level of MAXHIGH, or DEFAULT should cause the LED to glow, while those with lower priority (LOW and MIN) should not.

The user's control over notifications should extend to the LED. When you use DEFAULT_LIGHTS, the LED will glow white. Your notifications shouldn't use a different color unless the user has explicitly customized it.

Building Notifications That Users Care About //建立用户关心的通知


To create an app that users love, it is important to design your notifications carefully. Notifications embody your app's voice, and contribute to your app's personality. Unwanted or unimportant notifications can annoy the user or make them resent how much attention the app wants from them, so use notifications judiciously.

When to display a notification //何时显示通知

To create an application that people enjoy using, it's important to recognize that the user's attention and focus is a resource that must be protected. While Android's notification system has been designed to minimize the impact of notifications on the user's attention, it is still important to be aware of the fact that notifications are interrupting the user's task flow. As you plan your notifications, ask yourself if they are important enough to warrant an interruption. If you are unsure, allow the user to opt into a notification using your apps notification settings, or adjust the notifications priority flag to LOW or MIN to avoid distracting the user while they are doing something else.


Examples of time-sensitive notification

While well-behaved apps generally only speak when spoken to, a few cases do merit an app's interrupting the user with an unprompted notification.

Use notifications primarily for time-sensitive events, especially if these synchronous events involve other people. For instance, an incoming chat is a real-time and synchronous form of communication: Another user actively waiting on your response. Calendar events are another good example of when to use a notification and grab the user's attention, because the event is imminent, and calendar events often involve other people.

When not to display a notification //何时不显示通知

 

In many other cases, notifications aren't appropriate:

  • Avoid notifying the user of information that is not directed specifically at them, or information that is not truly time-sensitive. For instance, the asynchronous and undirected updates flowing through a social network generally do not warrant a real-time interruption. For the users who do care about them, allow them to opt-in.
  • Don't create a notification if the relevant new information is currently on screen. Instead, use the UI of the application itself to notify the user of new information directly in context. For instance, a chat application should not create system notifications while the user is actively chatting with another user.
  • Don't interrupt the user for low-level technical operations, like saving or syncing information, or updating an application if the app or system can resolve the issue without involving the user.
  • Don't interrupt the user to inform them of an error if it is possible for the application to recover from the error on its own without the user taking any action.
  • Don't create notifications that have no true notification content and merely advertise your app. A notification should provide useful, timely, new information and should not be used merely to launch an app.
  • Don't create superfluous notifications just to get your brand in front of users. Such notifications frustrate and likely alienate your audience. The best way to provide small amounts of updated information and keep them engaged with your app is to develop a widget that they can choose to place on their home screen.

Interacting with Notifications //通知交互


Notifications are indicated by icons in the status bar, and can be accessed by opening the notification drawer.

Touching a notification opens the associated app to detailed content that matches the notification. Swiping left or right on a notification removes it from the drawer.

Ongoing notifications //持续通知

 

Ongoing notifications keep users informed about an ongoing process in the background. For example, music players announce the currently playing track in the notification system and continue to do so until the user stops the playback. Ongoing notifications can also show the user feedback for longer tasks like downloading a file, or encoding a video. A user cannot manually remove an ongoing notification from the notification drawer.

Media playback //媒体播放

In Android 5.0, the lock screen doesn't show transport controls for the deprecated RemoteControlClient class. But it does show notifications, so each app's playback notification is now the primary way for users to control playback from a locked state. This behavior gives apps more control over which buttons to show, and in what way, while providing a consistent experience for the user whether or not the screen is locked.

Dialogs and toasts //对话框和Toast

Your app should not create a dialog or toast if it is not currently on screen. A dialog or toast should only be displayed as an immediate response to the user taking an action inside of your app. For further guidance on the use of dialogs and toasts, refer to Confirming & Acknowledging.

Ranking and ordering //等级和排序

Notifications are news, and so are essentially shown in reverse-chronological order, with special consideration given to the app's stated notification priority.

Notifications are a key part of the lock screen, and are featured prominently every time the device display comes on. Space on the lock screen is tight, so it is more important than ever to identify the most urgent or relevant notifications. For this reason, Android has a more sophisticated sorting algorithm for notifications, taking into account:

  • The timestamp and application's stated priority.
  • Whether the notification has recently disturbed the user with sound or vibration. (That is, if the phone just made a noise, and the user wants to know "What just happened?", the lock screen should answer that at a glance.)
  • Any people attached to the notification using EXTRA_PEOPLE, and, in particular, whether they are starred contacts.

To best take advantage of this sorting, focus on the user experience you want to create, rather than aiming for any particular spot on the list.


On the lock screen //在锁屏界面

Because notifications are visible on the lock screen, user privacy is an especially important consideration. Notifications often contain sensitive information, and should not necessarily be visible to anyone who picks up the device and turns on the display.

  • For devices that have a secure lock screen (PIN, pattern, or password), the interface has public and private parts. The public interface can be displayed on a secure lock screen and therefore seen by anyone. The private interface is the world behind that lock screen, and is only revealed once the user has signed into the device.

User control over information displayed on the secure lock screen 


Notifications on the lock screen, with contents revealed after the user unlocks the device.

When setting up a secure lock screen, the user can choose to conceal sensitive details from the secure lock screen. In this case the System UI considers the notification's visibility level to figure out what can safely be shown.

To control the visibility level, callNotification.Builder.setVisibility(), and specify one of these values:

  • VISIBILITY_PUBLIC. Shows the notification's full content. This is the system default if visibility is left unspecified.
  • VISIBILITY_PRIVATE. On the lock screen, shows basic information about the existence of this notification, including its icon and the name of the app that posted it. The rest of the notification's details are not displayed. A couple of good points to keep in mind are as follows:
    • If you want to provide a different public version of your notification for the system to display on a secure lock screen, supply a replacement Notification object in theNotification.publicVersion field.
    • This setting gives your app an opportunity to create a redacted version of the content that is still useful but does not reveal personal information. Consider the example of an SMS app whose notifications include the text of the SMS and the sender's name and contact icon. This notification should be VISIBILITY_PRIVATE, but publicVersion could still contain useful information like "3 new messages" without any other identifying details.
  • Notification.VISIBILITY_SECRET. Shows only the most minimal information, excluding even the notification's icon.

Notifications on Android Wear //在可穿戴设备上的通知


Notifications and their actions are bridged over to Wear devices by default. Developers can control which notifications bridge from the phone to the watch, and vice-versa. Developers can also control which actions bridge, as well. If your app includes actions that can't be accomplished with a single tap, either hide these actions on your Wear notification or consider hooking them up to a Wear app, thus allowing the user to finish the action on their watch.

Bridging notifications and actions //桥接通知和动作

A connected device, such as a phone, can bridge notifications to a Wear device, so that the notifications are displayed there. Similarly, it can bridge actions, so that the user can act on the notifications right from the Wear device.

Bridge

  • New instant messages
  • Single-tap actions such as +1, Like, Heart

Don't bridge

  • Notifications of newly arrived podcasts
  • Actions that map to features that aren't possible on the watch

Unique actions to define for Wear //为wear定义惟一的动作

There are some actions that you can perform only on Wear. These include the following:

  • Quick lists of canned responses such as "Be right back"
  • Open on the phone
  • A "Comment" or "Reply" action that brings up the speech input screen
  • Actions that launch Wear-specific apps
原文地址:https://www.cnblogs.com/bvin/p/4303502.html