所以我想为我的应用程序创建一个通知提醒。但是当我想创建一个通知通道时,我已经在互联网和文档中查看了代码,但是getSystemService方法显示了一个错误。
Type mismatch: inferred type is String but Class<TypeVariable(T)!> was expected
我的准则
private fun createNotificationChannel()
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
val name = "Notif Channel"
val desc = "A Description of the Channel"
val importance = NotificationManager.IMPORTANCE_DEFAULT
val channel = NotificationChannel(channelID, name, importance)
channel.description = desc
//line below error
val notificationManager = getSystemService(requireContext(), NOTIFICATION_SERVICE) as NotificationManager
//----------------
notificationManager.createNotificationChannel(channel)
}
}
有人知道怎么处理这个吗?
2条答案
按热度按时间7kjnsjlb1#
正确的用法是:
或
66bbxpm52#
另一种使用方法是: