Last active
May 13, 2024 21:43
-
-
Save bowserf/b9acb033d1ea5b8e4968154fdef596c4 to your computer and use it in GitHub Desktop.
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
import android.graphics.Color | |
import androidx.core.app.NotificationCompat | |
import androidx.core.app.NotificationManagerCompat | |
import com.sample_app.R | |
private const val MESSAGES_CHANNEL_ID = "notification_channel_id" | |
private const val NOTIFICATION_ID = 123456 | |
fun pushMessageNotification() { | |
... | |
val chatMessageStyle = createMessageNotificationStyle( | |
userName = "Olivia", | |
userProfileBitmap = notificationIcon, | |
text = "Hello! How are you?", | |
) | |
val notification = NotificationCompat.Builder( | |
context, | |
MESSAGES_CHANNEL_ID, | |
) | |
// no "setContentTitle" nor "setContentText" because | |
// information is contained in "chatMessageStyle" that | |
// we apply by calling "setStyle" | |
.setStyle(chatMessageStyle) | |
.setContentIntent(pendingIntent) | |
.setSmallIcon(R.drawable.ic_android_black_24dp) | |
.setAutoCancel(true) | |
.setCategory(NotificationCompat.CATEGORY_MESSAGE) | |
.build() | |
NotificationManagerCompat.from(context).notify(NOTIFICATION_ID, notification) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment