1 page.title=Notifications 2 page.tags="notifications","design","L" 3 @jd:body 4 5 <a class="notice-developers" href="{@docRoot}training/notify-user/index.html"> 6 <div> 7 <h3>Developer Docs</h3> 8 <p>Notifying the User</p> 9 </div> 10 </a> 11 12 <a class="notice-designers" href="notifications_k.html"> 13 <div> 14 <h3>Notifications in Android 4.4 and Lower</h3> 15 </div> 16 </a> 17 18 <style> 19 .col-5, .col-6, .col-7 { 20 margin-left:0px; 21 } 22 </style> 23 24 <p>The notification system allows users to keep informed about relevant and 25 timely 26 events in your app, such as new chat messages from a friend or a calendar event. 27 Think of notifications as a news channel that alerts the user to important 28 events as 29 they happen or a log that chronicles events while the user is not paying 30 attention—and one that is synced as appropriate across all their Android devices.</p> 31 32 <h4 id="New"><strong>New in Android 5.0</strong></h4> 33 34 <p>In Android 5.0, notifications receive important updates: structurally, 35 visually, and functionally:</p> 36 37 <ul> 38 <li>Notifications have undergone visual changes consistent with the new 39 material design theme.</li> 40 <li> Notifications are now available on the device lock screen, while 41 sensitive content can still 42 be hidden behind it.</li> 43 <li>High-priority notifications received while the device is in use now use a new format called 44 heads-up notifications.</li> 45 <li>Cloud-synced notifications: Dismissing a notification on one of your 46 Android devices dismisses it 47 on the others, as well.</li> 48 </ul> 49 50 <p class="note"><strong>Note:</strong> Notification design in this version of 51 Android is a significant 52 departure from that of previous versions. For information about notification design in previous 53 versions, see <a href="./notifications_k.html">Notifications in Android 4.4 and lower</a>.</p> 54 55 <h2 id="Anatomy">Anatomy of a Notification</h2> 56 57 <p>This section goes over basic parts of a notification and how they can 58 appear on different types of devices.</p> 59 60 <h3 id="BaseLayout">Base layout</h3> 61 62 <p>At a minimum, all notifications consist of a base layout, including:</p> 63 64 <ul> 65 <li> The notification's <strong>icon</strong>. The icon symbolizes the 66 originating app. It may also 67 potentially indicate notification type if the app generates more than one 68 type.</li> 69 <li> A notification <strong>title</strong> and additional 70 <strong>text</strong>.</li> 71 <li> A <strong>timestamp</strong>.</li> 72 </ul> 73 74 <p>Notifications created with {@link android.app.Notification.Builder Notification.Builder} 75 for previous platform versions look and work the same in Android 76 5.0, with only minor stylistic changes that the system handles 77 for you. For more information about notifications on previous versions of 78 Android, see 79 <a href="./notifications_k.html">Notifications in Android 4.4 and lower</a>.</p></p> 80 81 82 <img style="margin:20px 0 0 0" 83 src="{@docRoot}images/android-5.0/notifications/basic_combo.png" 84 alt="" width="700px" /> 85 86 87 <div style="clear:both;margin-top:20px"> 88 <p class="img-caption"> 89 Base layout of a handheld notification (left) and the same notification on Wear (right), 90 with a user photo and a notification icon 91 </p> 92 </div> 93 94 <h3 id="ExpandedLayouts">Expanded layouts</h3> 95 96 97 <p>You can choose how much detail your app's notifications should 98 provide. They can show the first 99 few lines of a message or show a larger image preview. The additional 100 information provides the user with more 101 context, and—in some cases—may allow the user to read a message in its 102 entirety. The user can 103 pinch-zoom or perform a single-finger glide to toggle between compact 104 and expanded layouts. 105 For single-event notifications, Android provides three expanded layout 106 templates (text, inbox, and 107 image) for you to use in your application. The following images show you how 108 single-event notifications look on 109 handhelds (left) and wearables (right).</p> 110 111 <img style="margin-top:30px" 112 src="{@docRoot}images/android-5.0/notifications/expandedtext_combo.png" 113 alt="" width="700px" height;="284px" /> 114 <img style="margin-top:30px" 115 src="{@docRoot}images/android-5.0/notifications/stack_combo.png" 116 alt="" width="700px" height;="284px" /> 117 <img style="margin-top:30px" 118 src="{@docRoot}images/android-5.0/notifications/ExpandedImage.png" 119 alt="" width="311px" height;="450px" /> 120 121 <h3 id="actions" style="clear:both; margin-top:40px">Actions</h3> 122 123 <p>Android supports optional actions that are displayed at the bottom 124 of the notification. 125 With actions, users can handle the most common tasks for a particular 126 notification from within the notification shade without having to open the 127 originating application. 128 This speeds up interaction and, in conjunction with swipe-to-dismiss, helps users focus on 129 notifications that matter to them.</p> 130 131 132 <img src="{@docRoot}images/android-5.0/notifications/action_combo.png" 133 alt="" width="700px" /> 134 135 136 137 <p style="clear:both">Be judicious with how many actions you include with a 138 notification. The more 139 actions you include, the more cognitive complexity you create. Limit yourself 140 to the smallest number 141 of actions possible by only including the most imminently important and 142 meaningful actions.</p> 143 144 <p>Good candidates for actions on notifications are actions that:</p> 145 146 <ul> 147 <li> Are essential, frequent, and typical for the content type you're 148 displaying 149 <li> Allow the user to accomplish tasks quickly 150 </ul> 151 152 <p>Avoid actions that are:</p> 153 154 <ul> 155 <li> Ambiguous 156 <li> The same as the default action of the notification (such as "Read" or 157 "Open") 158 </ul> 159 160 161 162 <p>You can specify a maximum of three actions, each consisting of an action 163 icon and name. 164 Adding actions to a simple base layout makes the notification expandable, 165 even if the 166 notification doesn't have an expanded layout. Since actions are only shown for 167 expanded 168 notifications and are otherwise hidden, make sure that any action a 169 user can invoke from 170 a notification is available from within the associated application, as 171 well.</p> 172 173 <h2 style="clear:left">Heads-up Notification</h2> 174 <div class="figure" style="width:311px"> 175 <img src="{@docRoot}images/android-5.0/notifications/hun-example.png" 176 alt="" width="311px" /> 177 <p class="img-caption"> 178 Example of a heads-up notification (incoming phone call, high priority) 179 appearing on top of an 180 immersive app 181 </p> 182 </div> 183 184 <p>When a high-priority notification arrives (see right), it is presented 185 to users for a 186 short period of time with an expanded layout exposing possible actions.</p> 187 <p> After this period of time, the notification retreats to the notification 188 shade. If a notification's <a href="#correctly_set_and_manage_notification_priority">priority</a> is 189 flagged as High, Max, or full-screen, it gets a heads-up notification.</p> 190 191 <p><b>Good examples of heads-up notifications</b></p> 192 193 <ul> 194 <li> Incoming phone call when using a device</li> 195 <li> Alarm when using a device</li> 196 <li> New SMS message</li> 197 <li> Low battery</li> 198 </ul> 199 200 <h2 style="clear:both" id="guidelines">Guidelines</h2> 201 202 203 <h3 id="MakeItPersonal">Make it personal</h3> 204 205 <p>For notifications of items sent by another person (such as a message or 206 status update), include that person's image using 207 {@link android.app.Notification.Builder#setLargeIcon setLargeIcon()}. Also attach information about 208 the person to the notification's metadata (see {@link android.app.Notification#EXTRA_PEOPLE}).</p> 209 210 <p>Your notification's main icon is still shown, so the user can associate 211 it with the icon 212 visible in the status bar.</p> 213 214 215 <img src="{@docRoot}images/android-5.0/notifications/Triggered.png" 216 alt="" width="311px"/> 217 <p style="margin-top:10px" class="img-caption"> 218 Notification that shows the person who triggered it and the content they sent. 219 </p> 220 221 222 <h3 id="navigate_to_the_right_place">Navigate to the right place</h3> 223 224 <p>When the user touches the body of a notification (outside of the action 225 buttons), open your app 226 to the place where the user can view and act upon the data referenced in the 227 notification. In most cases, this will be the detailed view of a single data item such as a message, 228 but it might also be a 229 summary view if the notification is stacked. If your app takes the 230 user anywhere below your app's top level, insert navigation into your app's back stack so that the 231 user can press the system back button to return to the top level. For more information, see 232 <em>Navigation into Your App via Home Screen Widgets and Notifications</em> in the <a 233 href="{@docRoot}design/patterns/navigation.html#into-your-app">Navigation</a> 234 design pattern.</p> 235 236 <h3 id="correctly_set_and_manage_notification_priority">Correctly set and 237 manage notification 238 priority</h3> 239 240 <p>Android supports a priority flag for notifications. This flag allows you to 241 influence where your notification appears, relative to other notifications, and 242 helps ensure 243 that users always see their most important notifications first. You can choose 244 from the 245 following priority levels when posting a notification:</p> 246 <table> 247 <tr> 248 <td class="tab0"> 249 <p><strong>Priority</strong></p> 250 </td> 251 <td class="tab0"> 252 <p><strong>Use</strong></p> 253 </td> 254 </tr> 255 <tr> 256 <td class="tab1"> 257 <p><code>MAX</code></p> 258 </td> 259 <td class="tab1"> 260 <p>Use for critical and urgent notifications that alert the user to a condition 261 that is 262 time-critical or needs to be resolved before they can continue with a 263 particular task.</p> 264 </td> 265 </tr> 266 <tr> 267 <td class="tab1"> 268 <p><code>HIGH</code></p> 269 </td> 270 <td class="tab1"> 271 <p>Use primarily for important communication, such as message or chat 272 events with content that is particularly interesting for the user. 273 High-priority notifications trigger the heads-up notification display.</p> 274 </td> 275 </tr> 276 <tr> 277 <td class="tab1"> 278 <p><code>DEFAULT</code></p> 279 </td> 280 <td class="tab1"> 281 <p>Use for all notifications that don't fall into any of the other priorities described here.</p> 282 </td> 283 </tr> 284 <tr> 285 <td class="tab1"> 286 <p><code>LOW</code></p> 287 </td> 288 <td class="tab1"> 289 <p>Use for notifications that you want the user to be informed about, but 290 that are less urgent. Low-priority notifications tend to show up at the bottom of the list, 291 which makes them a good 292 choice for things like public or undirected social updates: The user has asked to 293 be notified about 294 them, but these notifications should never take precedence over urgent or direct 295 communication.</p> 296 </td> 297 </tr> 298 <tr> 299 <td class="tab1"> 300 <p><code>MIN</code></p> 301 </td> 302 <td class="tab1"> 303 <p>Use for contextual or background information such as weather information or contextual 304 location information. 305 Minimum-priority notifications do not appear in the status bar. The user 306 discovers them on expanding the notification shade.</p> 307 </td> 308 </tr> 309 </table> 310 311 312 <h4 id="how_to_choose_an_appropriate_priority"><strong>How to choose an 313 appropriate 314 priority</strong></h4> 315 316 <p><code>DEFAULT</code>, <code>HIGH</code>, and <code>MAX</code> are interruptive priority levels, and risk 317 interrupting the user 318 in mid-activity. To avoid annoying your app's users, reserve interruptive priority levels for 319 notifications that:</p> 320 321 <ul> 322 <li> Involve another person</li> 323 <li> Are time-sensitive</li> 324 <li> Might immediately change the user's behavior in the real world</li> 325 </ul> 326 327 <p>Notifications set to <code>LOW</code> and <code>MIN</code> can still be 328 valuable for the user: Many, if not most, notifications just don't need to command the user's 329 immediate attention, or vibrate the user's wrist, yet contain information that the user will find 330 valuable when they choose to 331 look for notifications. Criteria for <code>LOW</code> and <code>MIN</code> 332 priority notifications include:</p> 333 334 <ul> 335 <li> Don't involve other people</li> 336 <li> Aren't time sensitive</li> 337 <li> Contain content the user might be interested in but could choose to 338 browse at their leisure</li> 339 </ul> 340 341 342 <img 343 src="{@docRoot}images/android-5.0/notifications/notifications_pattern_priority.png" 344 alt="" width="700"/> 345 346 347 <h3 style="clear:both" id="set_a_notification_category">Set a notification 348 category</h3> 349 350 <p>If your notification falls into one of the predefined categories (see 351 below), assign it 352 accordingly. Aspects of the system UI such as the notification shade (or any 353 other notification 354 listener) may use this information to make ranking and filtering decisions.</p> 355 <table> 356 <tr> 357 <td> 358 <p><code><a 359 href="/reference/android/app/Notification.html#CATEGORY_CALL">CATEGORY_CALL</a></code></p> 360 </td> 361 <td> 362 <p>Incoming call (voice or video) or similar synchronous communication 363 request</p> 364 </td> 365 </tr> 366 <tr> 367 <td> 368 <p><code><a 369 href="/reference/android/app/Notification.html#CATEGORY_MESSAGE">CATEGORY_MESSAGE</a></code></p> 370 </td> 371 <td> 372 <p>Incoming direct message (SMS, instant message, etc.)</p> 373 </td> 374 </tr> 375 <tr> 376 <td> 377 <p><code><a 378 href="/reference/android/app/Notification.html#CATEGORY_EMAIL">CATEGORY_EMAIL</a></code></p> 379 </td> 380 <td> 381 <p>Asynchronous bulk message (email)</p> 382 </td> 383 </tr> 384 <tr> 385 <td> 386 <p><code><a 387 href="/reference/android/app/Notification.html#CATEGORY_EVENT">CATEGORY_EVENT</a></code></p> 388 </td> 389 <td> 390 <p>Calendar event</p> 391 </td> 392 </tr> 393 <tr> 394 <td> 395 <p><code><a 396 href="/reference/android/app/Notification.html#CATEGORY_PROMO">CATEGORY_PROMO</a></code></p> 397 </td> 398 <td> 399 <p>Promotion or advertisement</p> 400 </td> 401 </tr> 402 <tr> 403 <td> 404 <p><code><a 405 href="/reference/android/app/Notification.html#CATEGORY_ALARM">CATEGORY_ALARM</a></code></p> 406 </td> 407 <td> 408 <p>Alarm or timer</p> 409 </td> 410 </tr> 411 <tr> 412 <td> 413 <p><code><a 414 href="/reference/android/app/Notification.html#CATEGORY_PROGRESS">CATEGORY_PROGRESS</a></code></p> 415 </td> 416 <td> 417 <p>Progress of a long-running background operation</p> 418 </td> 419 </tr> 420 <tr> 421 <td> 422 <p><code><a 423 href="/reference/android/app/Notification.html#CATEGORY_SOCIAL">CATEGORY_SOCIAL</a></code></p> 424 </td> 425 <td> 426 <p>Social network or sharing update</p> 427 </td> 428 </tr> 429 <tr> 430 <td> 431 <p><code><a 432 href="/reference/android/app/Notification.html#CATEGORY_ERROR">CATEGORY_ERROR</a></code></p> 433 </td> 434 <td> 435 <p>Error in background operation or authentication status</p> 436 </td> 437 </tr> 438 <tr> 439 <td> 440 <p><code><a 441 href="/reference/android/app/Notification.html#CATEGORY_TRANSPORT">CATEGORY_TRANSPORT</a></code></p> 442 </td> 443 <td> 444 <p>Media transport control for playback</p> 445 </td> 446 </tr> 447 <tr> 448 <td> 449 <p><code><a 450 href="/reference/android/app/Notification.html#CATEGORY_SYSTEM">CATEGORY_SYSTEM</a></code></p> 451 </td> 452 <td> 453 <p>System or device status update. Reserved for system use.</p> 454 </td> 455 </tr> 456 <tr> 457 <td> 458 <p><code><a 459 href="/reference/android/app/Notification.html#CATEGORY_SERVICE">CATEGORY_SERVICE</a></code></p> 460 </td> 461 <td> 462 <p>Indication of running background service</p> 463 </td> 464 </tr> 465 <tr> 466 <td> 467 <p><code><a 468 href="/reference/android/app/Notification.html#CATEGORY_RECOMMENDATION">CATEGORY_RECOMMENDATION</a></code></p> 469 </td> 470 <td> 471 <p>A specific, timely recommendation for a single thing. For example, a news 472 app might want to 473 recommend a news story it believes the user will want to read next.</p> 474 </td> 475 </tr> 476 <tr> 477 <td> 478 <p><code><a 479 href="/reference/android/app/Notification.html#CATEGORY_STATUS">CATEGORY_STATUS</a></code></p> 480 </td> 481 <td> 482 <p>Ongoing information about device or contextual status</p> 483 </td> 484 </tr> 485 </table> 486 487 <h3 id="summarize_your_notifications">Summarize your notifications</h3> 488 489 <p>If a notification of a certain type is already pending when your app tries to send a new 490 notification of the same type, combine them into a single summary notification for the app. Do not 491 create a new object.</p> 492 493 <p>A summary notification builds a summary description and allows the user to 494 understand how many 495 notifications of a particular kind are pending.</p> 496 497 <div class="col-6"> 498 499 <p><strong>Don't</strong></p> 500 <img src="{@docRoot}images/android-5.0/notifications/Summarise_Dont.png" 501 alt="" width="311px" /> 502 </div> 503 504 <div> 505 <p><strong>Do</strong></p> 506 507 <img src="{@docRoot}images/android-5.0/notifications/Summarise_Do.png" 508 alt="" width="311px"/> 509 </div> 510 511 <p style="clear:left; padding-top:30px; padding-bottom:20px">You can provide 512 more detail about the individual notifications that make up a 513 summary by using the expanded digest layout. This approach allows users to gain a 514 better sense of which 515 notifications are pending and if they are interesting enough to read in 516 detail within the 517 associated app.</p> 518 <div class="col-6"> 519 <img src="{@docRoot}images/android-5.0/notifications/Stack.png" 520 style="margin-bottom:20px" 521 alt="" width="311px" /> 522 <p class="img-caption"> 523 Expanded and contracted notification that is a summary (using <code>InboxStyle</code>) 524 </p> 525 </div> 526 527 <h3 style="clear:both" id="make_notifications_optional">Make notifications 528 optional</h3> 529 530 <p>Users should always be in control of notifications. Allow the user to 531 disable your app's 532 notifications or change their alert properties, such as alert sound and whether 533 to use vibration, 534 by adding a notification settings item to your application settings.</p> 535 536 <h3 id="use_distinct_icons">Use distinct icons</h3> 537 <p>By glancing at the notification area, the user should be able to discern 538 what kinds of 539 notifications are currently pending.</p> 540 541 <div class="figure"> 542 <img src="{@docRoot}images/android-5.0/notifications/ProductIcons.png" 543 alt="" width="420" /> 544 </div> 545 546 <div><p><strong>Do</strong></p> 547 <p>Look at the notification icons Android apps already provide and create 548 notification icons for 549 your app that are sufficiently distinct in appearance.</p> 550 551 <p><strong>Do</strong></p> 552 <p>Use the proper <a 553 href="/design/style/iconography.html#notification">notification icon style</a> 554 for small icons, and the Material Light 555 <a href="/design/style/iconography.html#action-bar">action bar icon 556 style</a> for your action 557 icons.</p> 558 <p ><strong>Do</strong></p> 559 <p >Keep your icons visually simple, avoiding excessive detail that is hard to 560 discern.</p> 561 562 <div><p><strong>Don't</strong></p> 563 <p>Place any additional alpha (dimming or fading) into your 564 small icons and action 565 icons; they can have anti-aliased edges, but because Android uses these 566 icons as masks (that is, only 567 the alpha channel is used), the image should generally be drawn at full 568 opacity.</p> 569 570 </div> 571 <p style="clear:both"><strong>Don't</strong></p> 572 573 <p>Use color to distinguish your app from others. Notification icons should 574 only be a white-on-transparent background image.</p> 575 576 577 <h3 id="pulse_the_notification_led_appropriately">Pulse the notification LED 578 appropriately</h3> 579 580 <p>Many Android devices contain a notification LED, which is used to keep the 581 user informed about 582 events while the screen is off. Notifications with a priority level of <code>MAX</code>, 583 <code>HIGH</code>, or <code>DEFAULT</code> should 584 cause the LED to glow, while those with lower priority (<code>LOW</code> and 585 <code>MIN</code>) should not.</p> 586 587 <p>The user's control over notifications should extend to the LED. When you use 588 DEFAULT_LIGHTS, the 589 LED will glow white. Your notifications shouldn't use a different 590 color unless the 591 user has explicitly customized it.</p> 592 593 <h2 id="building_notifications_that_users_care_about">Building Notifications 594 That Users Care About</h2> 595 596 <p>To create an app that users love, it is important to design your 597 notifications carefully. 598 Notifications embody your app's voice, and contribute to your app's 599 personality. Unwanted or 600 unimportant notifications can annoy the user or make them resent how much 601 attention the app wants 602 from them, so use notifications judiciously.</p> 603 604 <h3 id="when_to_display_a_notification">When to display a notification</h3> 605 606 <p>To create an application that people enjoy using, it's important to 607 recognize that the user's 608 attention and focus is a resource that must be protected. While Android's 609 notification system has 610 been designed to minimize the impact of notifications on the user's attention, 611 it is 612 still important to be aware of the fact that notifications are interrupting the 613 user's task flow. 614 As you plan your notifications, ask yourself if they are important enough to 615 warrant an interruption. If you are unsure, allow the user to opt into a 616 notification using your apps notification settings, or adjust 617 the notifications priority flag to <code>LOW</code> or <code>MIN</code> to 618 avoid distracting the user while they are doing 619 something else.</p> 620 621 <img src="{@docRoot}images/android-5.0/notifications/TimeSensitive.png" 622 alt="" width="311px" /> 623 <p style="margin-top:10px" class="img-caption"> 624 Examples of time-sensitive notification 625 </p> 626 627 <p>While well-behaved apps generally only speak when spoken to, a few cases 628 do merit an app's interrupting the user with an unprompted notification.</p> 629 630 <p>Use notifications primarily for <strong>time-sensitive events</strong>, especially 631 if these synchronous events <strong>involve other people</strong>. For 632 instance, an incoming chat 633 is a real-time and synchronous form of communication: Another user 634 actively waiting on your response. Calendar events are another good example of when to use a 635 notification and grab the 636 user's attention, because the event is imminent, and calendar events often 637 involve other people.</p> 638 639 <h3 style="clear:both" id="when_not_to_display_a_notification">When not to 640 display a notification</h3> 641 642 <div class="figure" style="margin-top:60px"> 643 <img src="{@docRoot}images/android-5.0/notifications/AntiSample1.png" 644 alt="" width="311px" /> 645 </div> 646 647 <p>In many other cases, notifications aren't appropriate:</p> 648 649 <ul> 650 <li> Avoid notifying the user of information that is not directed 651 specifically at them, or 652 information that is not truly time-sensitive. For instance, the asynchronous 653 and undirected updates 654 flowing through a social network generally do not warrant a real-time 655 interruption. For the users 656 who do care about them, allow them to opt-in.</li> 657 <li> Don't create a notification if the relevant new information is currently 658 on screen. Instead, 659 use the UI of the application itself to notify the user of new information 660 directly in context. 661 For instance, a chat application should not create system notifications while 662 the user is actively chatting with another user.</li> 663 <li> Don't interrupt the user for low-level technical operations, like saving 664 or syncing information, or updating an application if the app or system can resolve the issue 665 without involving the user.</li> 666 <li> Don't interrupt the user to inform them of an error if it is possible 667 for the application to recover from the error on its own without the user 668 taking any action.</li> 669 <li> Don't create notifications that have no true notification content and 670 merely advertise your 671 app. A notification should provide useful, timely, new information and should 672 not be used 673 merely to launch an app.</li> 674 <li> Don't create superfluous notifications just to get your brand in front 675 of users. 676 Such notifications frustrate and likely alienate your audience. The 677 best way to provide 678 small amounts of updated information and keep them engaged 679 with your 680 app is to develop a widget that they can choose to place on their 681 home screen.</li> 682 </ul> 683 684 <h2 style="clear:left" id="interacting_with_notifications">Interacting with 685 Notifications</h2> 686 687 <p>Notifications are indicated by icons in the status bar, and can be accessed 688 by opening the 689 notification drawer.</p> 690 691 <p>Touching a notification opens the associated app to detailed content 692 that matches the notification. 693 Swiping left or right on a notification removes it from the drawer.</p> 694 695 <h3 id="ongoing_notifications">Ongoing notifications</h3> 696 <div class="figure" style="width:311px"> 697 <img src="{@docRoot}images/android-5.0/notifications/MusicPlayback.png" 698 alt="" width="311px" /> 699 <p class="img-caption"> 700 Ongoing notification due to music playback 701 </p> 702 </div> 703 <p>Ongoing notifications keep users informed about an ongoing process in the 704 background. 705 For example, music players announce the currently playing track in the 706 notification system and 707 continue to do so until the user stops the playback. Ongoing notifications can also 708 show the user 709 feedback for longer tasks like downloading a file, or encoding a video. A user cannot manually 710 remove an ongoing notification from the notification drawer.</p> 711 712 <h3 id="ongoing_notifications">Media playback</h3> 713 <p>In Android 5.0, the lock screen doesn't show transport controls for the deprecated 714 {@link android.media.RemoteControlClient} class. But it <em>does</em> show notifications, so each 715 app's playback notification is now the primary 716 way for users to control playback from a locked state. This behavior gives apps more 717 control over which 718 buttons to show, and in what way, while providing a consistent experience for 719 the user whether or not the screen is locked.</p> 720 721 <h3 style="clear:both" 722 id="dialogs_and_toasts_are_for_feedback_not_notification">Dialogs 723 and toasts</h3> 724 725 <p>Your app should not create a dialog or toast if it is not currently on 726 screen. A dialog or toast 727 should only be displayed as an immediate response to the user taking an action 728 inside of your app. 729 For further guidance on the use of dialogs and toasts, refer to 730 <a href="/design/patterns/confirming-acknowledging.html">Confirming & Acknowledging</a>.</p> 731 732 <h3>Ranking and ordering</h3> 733 734 <p>Notifications are news, and so are essentially shown in 735 reverse-chronological order, with 736 special consideration given to the app's stated notification 737 <a href="#correctly_set_and_manage_notification_priority">priority</a>.</p> 738 739 <p>Notifications are a key part of the lock screen, and are featured prominently 740 every 741 time the device display comes on. Space on the lock screen is tight, so it 742 is more important 743 than ever to identify the most urgent or relevant notifications. For this 744 reason, Android has a 745 more sophisticated sorting algorithm for notifications, taking into account:</p> 746 747 <ul> 748 <li> The timestamp and application's stated priority.</li> 749 <li> Whether the notification has recently disturbed the user with sound or 750 vibration. (That is, 751 if the phone just made a noise, and the user wants to know "What just 752 happened?", the lock screen 753 should answer that at a glance.)</li> 754 <li> Any people attached to the notification using {@link android.app.Notification#EXTRA_PEOPLE}, 755 and, in particular, whether they are starred contacts.</li> 756 </ul> 757 758 <p>To best take advantage of this sorting, focus on the user 759 experience you want 760 to create, rather than aiming for any particular spot on the list.</p> 761 762 <img src="{@docRoot}images/android-5.0/notifications/AntiSample3.png" 763 alt="" width="700px" /> 764 765 <p class="img-caption" style="margin-top:10px">Gmail notifications are 766 default priority, so they 767 normally sort below messages from an instant messaging app like Hangouts, but 768 get a 769 temporary bump when new messages come in. 770 </p> 771 772 773 <h3>On the lock screen</h3> 774 775 <p>Because notifications are visible on the lock screen, user privacy is an 776 especially 777 important consideration. Notifications often contain sensitive information, and 778 should not necessarily be visible 779 to anyone who picks up the device and turns on the display.</p> 780 781 <ul> 782 <li> For devices that have a secure lock screen (PIN, pattern, or password), the interface has 783 public and private parts. The public interface can be displayed on a secure lock screen and 784 therefore seen by anyone. The private interface is the world behind that lock screen, and 785 is only revealed once the user has signed into the device.</li> 786 </ul> 787 788 <h3>User control over information displayed on the secure lock screen</h3> 789 <div class="figure" style="width:311px"> 790 <img src="{@docRoot}images/android-5.0/notifications/LockScreen.png" 791 alt="" width="311px" /> 792 <p class="img-caption"> 793 Notifications on the lock screen, with contents revealed after the user unlocks the device. 794 </p> 795 </div> 796 797 <p>When setting up a secure lock screen, the user can choose to conceal 798 sensitive details from the secure lock screen. In this case the System UI 799 considers the notification's <em>visibility level</em> to figure out what can 800 safely be shown.</p> 801 <p> To control the visibility level, call 802 <code><a 803 href="/reference/android/app/Notification.Builder.html#setVisibility(int)">Notification.Builder.setVisibility()</a></code>, 804 and specify one of these values:</p> 805 806 <ul> 807 <li><code><a 808 href="/reference/android/app/Notification.html#VISIBILITY_PUBLIC">VISIBILITY_PUBLIC</a></code>. 809 Shows the notification's full content. 810 This is the system default if visibility is left unspecified.</li> 811 <li><code><a 812 href="/reference/android/app/Notification.html#VISIBILITY_PRIVATE">VISIBILITY_PRIVATE</a></code>. 813 On the lock screen, shows basic information about the existence of this notification, including its 814 icon and the name of the app that posted it. The rest of the notification's details are not displayed. 815 A couple of good points to keep in mind are as follows: 816 <ul> 817 <li> If you want to provide a different public version of your notification 818 for the system to display on a secure lock screen, supply a replacement 819 Notification object in the <code><a 820 href="/reference/android/app/Notification.html#publicVersion">Notification.publicVersion</a></code> 821 field. 822 <li> This setting gives your app an opportunity to create a redacted version of the 823 content that is still useful but does not reveal personal information. Consider the example of an 824 SMS app whose notifications include the text of the SMS and the sender's name and contact icon. 825 This notification should be <code>VISIBILITY_PRIVATE</code>, but <code>publicVersion</code> could still 826 contain useful information like "3 new messages" without any other identifying 827 details. 828 </ul> 829 </li> 830 <li><code><a 831 href="/reference/android/app/Notification.html#VISIBILITY_SECRET">Notification.VISIBILITY_SECRET</A></code>. Shows only the most minimal information, excluding 832 even the notification's icon.</li> 833 </ul> 834 <h2 style="clear:both" id="notifications_on_android_wear">Notifications on 835 Android Wear</h2> 836 837 <p>Notifications and their <em>actions</em> are bridged over to Wear devices by default. 838 Developers can control which notifications bridge from the 839 phone to the watch, 840 and vice-versa. Developers can also control which actions bridge, as well. If 841 your app includes 842 actions that can't be accomplished with a single tap, either hide these actions 843 on your Wear 844 notification or consider hooking them up to a Wear app, thus allowing the user to 845 finish the action on 846 their watch.</p> 847 848 <h4>Bridging notifications and actions</h4> 849 850 <p>A connected device, such as a phone, can bridge notifications to a Wear device, so that the 851 notifications are displayed there. Similarly, it can bridge actions, so that the user can act 852 on the notifications right from the Wear device.</p> 853 854 <p><strong>Bridge</strong></p> 855 856 <ul> 857 <li> New instant messages</li> 858 <li> Single-tap actions such as +1, Like, Heart</li> 859 </ul> 860 861 <img src="{@docRoot}images/android-5.0/notifications/WearBasic.png" width="156px" 862 height="156px" 863 alt="" /> 864 865 <p><strong>Don't bridge</strong></p> 866 867 <ul> 868 <li> Notifications of newly arrived podcasts</li> 869 <li> Actions that map to features that aren't possible on the watch</li> 870 </ul> 871 872 873 874 <p><h4>Unique actions to define for Wear</h4></p> 875 876 <p>There are some actions that you can perform only on Wear. These include the following:</p> 877 878 <ul> 879 <li> Quick lists of canned responses such as "Be right back"</li> 880 <li> Open on the phone</li> 881 <li> A "Comment" or "Reply" action that brings up the speech input screen</li> 882 <li> Actions that launch Wear-specific apps</li> 883 </ul> 884 885 <img src="{@docRoot}images/android-5.0/notifications/ReplyAction.png" width="156px" 886 height="156px" 887 alt="" /> 888