Created
October 17, 2018 11:41
-
-
Save ajithvgiri/fdc769bc505f6f96862dae4ce655f188 to your computer and use it in GitHub Desktop.
Notification Handler
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
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) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please check this code @abdabdulsamad