gpt4 book ai didi

android - Android Oreo 上的 NotificationManagerCompat

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:20:53 27 4
gpt4 key购买 nike

有没有办法在使用 NotificationManagerCompatNotificationCompat 时在 Android Oreo 上设置 channel ?

最佳答案

由于 NotificationManagerCompat 只是一个使生活更轻松的包装类,您可以正常创建 channel :

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val name = getString(R.string.channel_title)
val description = getString(R.string.channel_description)
val importance = NotificationManager.IMPORTANCE_HIGH
val mChannel = NotificationChannel(CHANNEL_ID, name, importance)
mChannel.description = description
mChannel.enableLights(true)
mChannel.lightColor = Color.parseColor("#5B3C88")
mChannel.enableVibration(true)
mChannel.vibrationPattern = longArrayOf(100, 200, 300, 400, 500, 400, 300, 200, 400)
val manager = (context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager)
manager.createNotificationChannel(mChannel)
}

然后在发布通知时使用 NotificationManagerCompat,但不要忘记使用新的构造函数构造通知:

NotificationCompat.Builder(context, CHANNEL_ID)

关于android - Android Oreo 上的 NotificationManagerCompat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45878921/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com