【问题标题】:How to implement Notification in the native android side while making a Flutter plugin?制作Flutter插件时如何在原生android端实现Notification?
【发布时间】: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


    【解决方案1】:

    答案非常非常愚蠢。我没有为通知分配频道

    【讨论】:

      猜你喜欢
      • 2020-11-24
      • 2019-02-11
      • 2021-08-01
      • 2021-05-05
      • 1970-01-01
      • 1970-01-01
      • 2019-03-17
      • 2020-02-09
      • 1970-01-01
      相关资源
      最近更新 更多