Created
December 2, 2021 16:35
-
-
Save ngangavic/68646a44c1b33ee6d0addc65ad53600f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun sendNotification(messageBody: String) { | |
val channelId = getString(R.string.default_notification_channel_id) | |
val defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) | |
val notificationBuilder = NotificationCompat.Builder(this, channelId) | |
.setSmallIcon(R.drawable.ic_stat_name) | |
.setContentTitle(getString(R.string.fcm_message)) | |
.setContentText(messageBody) | |
.setAutoCancel(true) | |
.setSound(defaultSoundUri) | |
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager | |
// Since android Oreo notification channel is needed. | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | |
val channel = NotificationChannel(channelId, | |
"Water Drop", | |
NotificationManager.IMPORTANCE_HIGH) | |
notificationManager.createNotificationChannel(channel) | |
} | |
notificationBuilder.build().flags.and(Notification.FLAG_AUTO_CANCEL) | |
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment