增加 importance 参数

This commit is contained in:
renhaoting 2025-12-31 14:32:06 +08:00
parent dc0c47659b
commit cf70646ef3
2 changed files with 7 additions and 8 deletions

View File

@ -14,7 +14,6 @@ import com.remax.notification.R
import com.remax.notification.check.NotificationCheckController
import com.remax.notification.config.PushContent
import com.remax.notification.config.PushContentController
import com.remax.notification.controller.NotificationTriggerController
import com.remax.notification.newUtil.NotificationDatas
import com.remax.notification.service.NotificationKeepAliveServiceManager
import java.io.File
@ -406,7 +405,6 @@ class ResidentModelManger {
})
.build()
return GeneralNotificationData(
notificationId = type2notificationId[NotificationType.RESIDENT] ?: 0,
contentTitle = StringUtils.getString(R.string.noti_resident_title),

View File

@ -429,7 +429,7 @@ class NotificationUtil private constructor() {
.setAutoCancel(true)
.setContentIntent(pendingIntent)
showNotification(notificationId, builder.build(), channelName)
showNotification(notificationId, builder.build(), channelName, NotificationManager.IMPORTANCE_MAX)
}
@ -454,11 +454,12 @@ class NotificationUtil private constructor() {
private fun showNotification(notificationId: Int = System.currentTimeMillis().toInt(),
notification: Notification,
channelName: String) {
channelName: String,
importance: Int = NotificationManager.IMPORTANCE_DEFAULT) {
if (!isNotificationsEnabled()) {
PermissionUtil.checkPermission(Manifest.permission.POST_NOTIFICATIONS, object : PermissionUtil.ICallback() {
override fun onAllGranted() {
doShowNotification(notificationId, notification, channelName)
doShowNotification(notificationId, notification, channelName, importance)
}
override fun onPartialGranted() {
@ -468,14 +469,14 @@ class NotificationUtil private constructor() {
}
})
} else {
doShowNotification(notificationId, notification, channelName)
doShowNotification(notificationId, notification, channelName, importance)
}
}
@RequiresPermission(Manifest.permission.POST_NOTIFICATIONS)
private fun doShowNotification(notificationId: Int = System.currentTimeMillis().toInt(), notification: Notification, channelName: String) {
private fun doShowNotification(notificationId: Int = System.currentTimeMillis().toInt(), notification: Notification, channelName: String, importance: Int = NotificationManager.IMPORTANCE_DEFAULT) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && notificationManager.getNotificationChannel(notification.channelId) == null) {
createNotificationChannel(notification.channelId, channelName, NotificationCompat.PRIORITY_HIGH)
createNotificationChannel(notification.channelId, channelName, importance)
}
NotificationManagerCompat.from(mContext).notify(notificationId, notification)
}