Akash Singh
05/31/2023, 2:12 PMval sound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + context.packageName + "/raw/test_sms")
val notificationBuilder = NotificationCompat.Builder(context, channelId)
.setColor(CommonUtil.getColorFromAttr(R.attr.orange))
.setSmallIcon(R.drawable.notification_icon_transparent)
.setAutoCancel(true)
.setDeleteIntent(getDeleteIntent(context, data, payload))
.setContentIntent(getContentIntent(context, data))
.setSound(sound)
.setPriority(data.notificationPriority)
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val build = notificationBuilder.build()
build.flags.and(Notification.FLAG_AUTO_CANCEL)
data.notificationId?.let { notificationManager.notify(it, build)
For Notification Channel creation (Android O and above)
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val notificationChannel = NotificationChannel(data.channelId, data.channelName,
data.channelPriority ?: NotificationManager.IMPORTANCE_HIGH
)
notificationChannel.enableLights(true)
notificationChannel.lightColor = Color.RED
notificationChannel.enableVibration(true)
val sound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + context.packageName + "/raw/test_sms")
val audioAttributes = AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.setUsage(AudioAttributes.USAGE_ALARM)
.build()
notificationChannel.setSound(sound, audioAttributes)
data.channelDesc?.let {
notificationChannel.description = it
}
notificationManager.createNotificationChannel(notificationChannel)