android - 制作Flutter插件时如何在原生android端实现Notification?
问题描述
我正在开发一个 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())
// }
}
出于调试目的,我还没有安排通知。日志中也没有显示错误,它只是默默地失败。我怀疑我是如何获取小图标的。通过所有其他方式,我试图让应用程序崩溃的图标。
解决方案
答案非常非常愚蠢。我没有为通知分配频道
推荐阅读
- arrays - 制作一个可以一次性完成所有边框设置的数组
- angular - 如何在角度 7 中动态传递另一个组件中的组件
- sql-server - 仅当不存在时才插入 SQL 数据库
- python - 如何在 python 中制作具有精确键顺序的字典?
- java - 开发弹簧控制器时出现问题,每次我得到不明确的映射
- angular - 如何在订阅中读取对象(可观察)-angular 6
- swift - 如何从collectionView中的第二项开始?
- omnet++ - 为什么 OMNET++ 无法编译?
- django - Django REST Framework 文件上传不起作用
- javascript - ECMAScript 模板文字返回不同的结果