来源:Android development tutorial series 2018第43集
原作者:PRABEESH R K
Android Notification
1.A notification is a message that Android displays outside your app's UI to provide the user with reminders, communication from other people, or other timely information from your app.
2.Users can tap the notification to open your app or take an action directly from the notification.
3.Notifications appear to users in different locations and formats, such as an icon in the status bar, a more detailed entry in the notification drawer, and as a badge on the app's icon.
1.通知就是一条展示在你的app交互界面之外的提示用户的消息,它可能是来自其他人的通讯,或者来自你app的其他即时性消息。
2.用户们能通过点击这条通知来打开你的app或者处理这条通知。
3.展现给用户的通知会出现在不同的地方,以及有不同的表现形式。比如一个出现在状态栏的icon,一条展示在下拉通知栏中的详细信息,或者一个在你app图标上的标记。
1.When you issue a notification, it first appears as an icon in the status bar.
2.Users can swipe down on the status bar to open the notification drawer, where they can view more details and take actions with the notification.
1.当你发出一条通知,它首先会在状态栏上显示一个图标。
2.用户可以在打开的下拉通知栏中看到详细信息,以及处理这条通知。
Heads-up notification
1.Beginning with Android 5.0, notifications can briefly appear in a floating window called a heads-up notification.
2.This behavior is normally for important notifications that the user should know about immediately, and it appears only if the device is unlocked.
3.The heads-up notification appears the moment your app issues the notification and it disappears after a moment, but remains visible in the notification drawer as usual.
heads-up notification
1.从Android 5.0开始,通知可以短暂的通过浮动窗显示,这种通知叫做heads-up notification(抬头通知?)。
2.对于我们需要用户立即知道的重要通知,通常我们会用这种方式。这种通知只会在设备解锁状态下展示。
3.当你的app发出通知时,heads-up notification会展示片刻,然后隐藏掉,但是用户同样可以在下拉通知栏里看到它。
Lock screen Notification
1.Beginning with Android 5.0, notifications can appear on the lock screen.
2.You can programmatically set the level of detail visible in notifications posted by your app on a secure lock screen.
3.Users can use the system settings to choose the level of detail visible in lock screen notifications, including the option to disable all lock screen notifications.
4.Starting with Android 8.0, users can choose to disable or enable lock screen notifications for each notification channel.
Lock screen Notification
1.从Android 5.0开始,通知可以展示在锁屏界面上。
2.你可以通过代码设置展示在锁屏界面上的通知的详细程度。
3.用户可以在系统设置中设置锁屏界面的通知展示,包括完全不允许锁屏通知显示。
4.从Android 8.0开始,用户可以给每个通知来源选择是否允许通知展示在锁屏界面。
App icon badge Notification
1.In supported launchers on devices running Android 8.0 (API level 26) and higher, app icons indicate new notifications with a colored "badge" (also known as a "notification dot") on the corresponding app launcher icon.
2.Users can long-press on an app icon to see the notifications for that app. Users can then dismiss or act on notifications from that menu, similar to the notification drawer.
App icon badge Notification
1.在Android 8.0 (API level 26)以上的版本设备中,如果你的应用得到允许,app图标将能以一个带颜色的小标识的方式告诉用户有新通知。
2.用户可以长按app图标来查看应用的通知。用户可以在长按菜单栏中像在下拉通知栏中一样选择取消或处理该通知。
Notification anatomy
Notification anatomy
- Small icon: This is required and set with setSmallIcon().
- App name: This is provided by the system.
- Time stamp: This is provided by the system but you can override with setWhen() or hide it with setShowWhen(false).
- Large icon: This is optional(usually used only for contact photos; do not use it for your app icon) and set with setLargeIcon().
- Title: This is optional and set with setContentTitle().
- Text: This is optional and set with setContentText().
1.小图标:必须实现,通过setSmallIcon()方法设置。
2.应用名:由系统提供。
3.时间戳:由系统提供,不过你可以重写setWhen()来手动设置,或者调用setShowWhen(false)来隐藏它。
4.大图标:可选实现(通常用在显示联系人头像,不要用这个展示你的app图标)。可以通过setLargeIcon()方法来设置。
5.标题:可选实现。通过setContentTitle()方法设置。
6.文本:可选实现。通过setContentText()方法设置。
网友评论