I can receive the notification sent from Firebase Cloud Messaging and show it to android device in here
when I click notification from my app, I expect it will go inside my app. but when I click the notification from my app it just doesn't do anything. it seems it can't be clicked.
so how to make it go to inside my app when I click the notification. here is the code I use
creating channel using this code
class App : Application() {
override fun onCreate() {
super.onCreate()
createNotificationChannels()
}
private fun createNotificationChannels() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val infoChannel = NotificationChannel(
NOTIFICATION_CHANNEL_INFO,
NOTIFICATION_CHANNEL_INFO,
NotificationManager.IMPORTANCE_DEFAULT
)
val importantNews = NotificationChannel(
NOTIFICATION_EVENT_UPDATES,
NOTIFICATION_EVENT_UPDATES,
NotificationManager.IMPORTANCE_HIGH
)
val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannel(infoChannel)
notificationManager.createNotificationChannel(importantNews)
}
}
}
and build notification using this code
private fun setUpNotification(title: String, message: String, type: String, imagePath: String) {
val channel = if (type == "Event Updates") NOTIFICATION_EVENT_UPDATES else NOTIFICATION_CHANNEL_INFO
var notification = NotificationCompat.Builder(this, channel)
.setSmallIcon(R.drawable.ic_stat_ic_notification)
.setContentTitle(title)
.setContentText(message)
.setAutoCancel(true)
.setOnlyAlertOnce(true)
if (type == "Event Updates") {
notification = notification
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setCategory(NotificationCompat.CATEGORY_EVENT)
} else {
notification = notification
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setCategory(NotificationCompat.CATEGORY_MESSAGE)
}
if (imagePath.isNotEmpty()) {
Glide.with(this)
.asBitmap()
.load(imagePath)
.into(object: SimpleTarget<Bitmap>() {
override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
notification = notification.setLargeIcon(resource)
val build = notification.build()
notificationManager.notify(1, build)
}
})
} else {
val build = notification.build()
notificationManager.notify(1, build)
}
}
}