Pro Android with Kotlin


Download 5.42 Mb.
Pdf ko'rish
bet135/223
Sana04.11.2023
Hajmi5.42 Mb.
#1746807
1   ...   131   132   133   134   135   136   137   138   ...   223
Bog'liq
@de android telegram Pro Android with Kotlin Developing Modern Mobile

154
CHAPTER 8: APIs
There is also a notification channel settings UI you can call by using this:
val intent = Intent(
Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
intent.putExtra(Settings.EXTRA_APP_PACKAGE,
getPackageName())
intent.putExtra(Settings.EXTRA_CHANNEL_ID,
myNotificationChannel.getId())
startActivity(intent)
You can further organize notification channels by gathering them in groups, for example to 
separate work-related and private type channels. To create a group, you write the following:
val groupId = "my_group"
// The user-visible name of the group.
val groupName = "Group Name"
val notificationMngr =
getSystemService(Context.NOTIFICATION_SERVICE)
as NotificationManager
notificationMngr.createNotificationChannelGroup(
NotificationChannelGroup(groupId, groupName))
You can then add the group to each notification channel by using its setGroup() method.
Notification Badges
Starting with Android 8.0 (API level 26), once a notification arrives in the system, a 
notification badge will show up in the app’s icon. See, for example, Figure 
8-5
.
Figure 8-5. A notification badge
Table 8-6. Notification Badges
Method
Description
setShowBadge(Boolean)
This specifies whether to show the badge.
setNumber(Int)
Long-tapping an app icon with a badge will show the number of 
notifications that have arrived. You can tailor this number according to 
your needs by using this method.
setBadgeIconType(Int)
Long-tapping an app icon with a badge will show an icon associated 
with the notification. You can tailor the icon’s size by using this method. 
Possible values are given as constants in class NotificationCompat: 
BADGE_ICON_NONE, BADGE_ICON_SMALL, and BADGE_ICON_LARGE.
You can control this badge using one of the NotificationChannel methods listed in Table 
8-6
.



Download 5.42 Mb.

Do'stlaringiz bilan baham:
1   ...   131   132   133   134   135   136   137   138   ...   223




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling