Skip to content

Instantly share code, notes, and snippets.

@ajithvgiri
Created October 17, 2018 11:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajithvgiri/fdc769bc505f6f96862dae4ce655f188 to your computer and use it in GitHub Desktop.
Save ajithvgiri/fdc769bc505f6f96862dae4ce655f188 to your computer and use it in GitHub Desktop.
Notification Handler
val notificationBuilder = NotificationCompat.Builder(this, notificationChannel)
.setSmallIcon(R.drawable.ic_stat_notification)
.setChannelId(notificationChannel)
.setLargeIcon(BitmapFactory.decodeResource(resources, R.mipmap.ic_launcher))
//Notification title
.setContentTitle(if (notification.title.isNotEmpty()) {
notification.title
} else {
getString(R.string.app_name)
})
//Notification Content
.setContentText(if (notification.message.isNotEmpty()) {
notification.message
} else {
""
})
.setAutoCancel(true)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setStyle(NotificationCompat.BigTextStyle().bigText(if (notification.message.isNotEmpty()) {
notification.message
} else {
""
}))
.setContentIntent(notificationIntentHandler(this, notification)).build()
fun notificationIntentHandler(context: Context, notification: NotificationModel): PendingIntent {
val intent = Intent(context, HomeActivity::class.java)
intent.putExtra("notification_data", jsonNotificationData.toString())
intent.putExtra("notification_type", notification_type)
intent.putExtra("notification_channel", channelId)
return PendingIntent.getActivity(context, 1, intent, PendingIntent.FLAG_ONE_SHOT)
}
@ajithvgiri
Copy link
Author

Please check this code @abdabdulsamad

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment