Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,27 @@ class QuickNotifyPlugin: FlutterPlugin, MethodCallHandler {

private lateinit var notificationManager: NotificationManager

private final var channelCreated: Boolean = false

private val channelProps = object {
var id = "quick_notify"
var name = "quick_notify"
var importance = NotificationManager.IMPORTANCE_DEFAULT
}

private fun createChannel(){
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
notificationManager.createNotificationChannel(NotificationChannel(channelProps.id, channelProps.name, channelProps.importance))
channelCreated = true
}
}

override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
channel = MethodChannel(flutterPluginBinding.binaryMessenger, "quick_notify")
channel.setMethodCallHandler(this)
applicationContext = flutterPluginBinding.applicationContext
notificationManager = applicationContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
notificationManager.createNotificationChannel(NotificationChannel(channelProps.id, channelProps.name, channelProps.importance))
}
if (notificationManager.areNotificationsEnabled()) createChannel()
}

override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) {
Expand All @@ -56,6 +63,8 @@ class QuickNotifyPlugin: FlutterPlugin, MethodCallHandler {
result.notImplemented()
}
} else if (call.method == "notify") {
if(!channelCreated) createChannel()

val args = call.arguments as Map<String, Any>
val title = args["title"] as String
val content = args["content"] as String
Expand Down