Files
bitchat-android/app/src/main/java/com/bitchat/android/ui/NotificationManager.kt
T
2025-07-10 12:08:22 +02:00

42 lines
1.5 KiB
Kotlin

package com.bitchat.android.ui
import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.os.Build
import androidx.core.app.NotificationCompat
import com.bitchat.android.R
class NotificationManager(private val context: Context) {
private val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
private val channelId = "bitchat_notifications"
init {
createNotificationChannel()
}
private fun createNotificationChannel() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val name = "Bitchat Notifications"
val descriptionText = "Notifications for new messages and other events"
val importance = NotificationManager.IMPORTANCE_DEFAULT
val channel = NotificationChannel(channelId, name, importance).apply {
description = descriptionText
}
notificationManager.createNotificationChannel(channel)
}
}
fun showPrivateMessageNotification(sender: String, message: String) {
val builder = NotificationCompat.Builder(context, channelId)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle("New message from $sender")
.setContentText(message)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setAutoCancel(true)
notificationManager.notify(System.currentTimeMillis().toInt(), builder.build())
}
}