【发布时间】:2021-08-28 11:59:27
【问题描述】:
我正在开发一个 Flutter 插件,它需要我在 android 端本身安排通知。我正在调用下面的函数
fun setAlarm(){
val name = "ALARM_CHANNEL"
val descriptionText = "All alarms will be shown in this channel"
val importance = NotificationManager.IMPORTANCE_DEFAULT
val channel = NotificationChannel("CHANNEL_ID", name, importance).apply {
description = descriptionText
}
val notificationManager: NotificationManager =
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannel(channel)
val builder= NotificationCompat.Builder(context, "SCREEN")
.setSmallIcon(context.resources.getIdentifier("ic_access_alarms", "drawable", context.packageName))
.setContentTitle("Title")
.setContentText("Body")
.setPriority(NotificationCompat.PRIORITY_HIGH)
notificationManager.notify(Random.nextInt(), builder.build())
// Tried this as well, not working
// with(NotificationManagerCompat.from(context)){
// notify(Random.nextInt(), builder.build())
// }
}
出于调试目的,我尚未安排通知。日志中也没有显示错误,它只是默默地失败。我怀疑我是如何获取小图标的。通过所有其他方法,我试图让应用程序崩溃。
【问题讨论】:
标签: android flutter kotlin flutter-plugin