You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to prompt a notification from the background. Currently, I'm not sending any contents or headings and I am sending content_available: true
I've added the service extension and I can update the content as needed, but it does not display.
@Keep // Keep is required to prevent minification from renaming or removing your class
class NotificationServiceExtension : INotificationServiceExtension {
override fun onNotificationReceived(event: INotificationReceivedEvent) {
val notification = event.notification
Log.d("NotificationServiceExtension", "Notification received with additional data: ${notification.additionalData}")
// Customize the notification
val builder = NotificationCompat.Builder(event.context, "default_channel_id")
.setColor(-0xc87c66) // Example color
.setContentTitle("New ${notification.additionalData?.get("type") ?: ""} review")
.setContentText("Check out the latest review for ${notification.additionalData?.get("location") ?: ""}!")
.setSmallIcon(android.R.drawable.ic_notification_overlay) // Set your own icon here
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
// Add custom actions (optional)
notification.actionButtons?.forEach { button ->
builder.addAction(0, button.text, null) // You can add actions here if needed
}
// Trigger the notification to display
val notificationManager = event.context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.notify(123, builder.build())
Log.d("NotificationServiceExtension", "Post builder")
// Optionally, if you need to perform additional background work or stop the notification from showing immediately
// Use event.preventDefault() to delay or stop its display until you've finished custom logic
event.notification.display()
}
}
Code of Conduct
I agree to follow this project's Code of Conduct
The text was updated successfully, but these errors were encountered:
How can we help?
I'm trying to prompt a notification from the background. Currently, I'm not sending any
contents
orheadings
and I am sendingcontent_available: true
I've added the service extension and I can update the content as needed, but it does not display.
Code of Conduct
The text was updated successfully, but these errors were encountered: