Set different notif channel names
This commit is contained in:
parent
4f75b259fa
commit
4897ed89e9
@ -1,12 +1,15 @@
|
||||
package org.unifiedpush.distributor.nextpush.services
|
||||
|
||||
import android.Manifest
|
||||
import android.app.Notification
|
||||
import android.app.NotificationChannel
|
||||
import android.app.NotificationManager
|
||||
import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.app.NotificationManagerCompat
|
||||
import org.unifiedpush.distributor.nextpush.R
|
||||
import org.unifiedpush.distributor.nextpush.activities.MainActivity
|
||||
@ -19,15 +22,14 @@ object NotificationUtils {
|
||||
private var warningShown = false
|
||||
|
||||
fun createForegroundNotification(context: Context): Notification {
|
||||
val appName = context.getString(R.string.app_name)
|
||||
val notificationChannelId = "$appName.Listener"
|
||||
val notificationChannelId = "${context.getString(R.string.app_name)}.Listener"
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
val notificationManager =
|
||||
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
val channel = NotificationChannel(
|
||||
notificationChannelId,
|
||||
appName,
|
||||
"Foreground service",
|
||||
NotificationManager.IMPORTANCE_LOW
|
||||
).let {
|
||||
it.description = context.getString(R.string.foreground_notif_description)
|
||||
@ -67,15 +69,14 @@ object NotificationUtils {
|
||||
fun createWarningNotification(context: Context) {
|
||||
if (warningShown)
|
||||
return
|
||||
val appName = context.getString(R.string.app_name)
|
||||
val notificationChannelId = "$appName.Warning"
|
||||
val notificationChannelId = "${context.getString(R.string.app_name)}.Warning"
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
val notificationManager =
|
||||
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
val channel = NotificationChannel(
|
||||
notificationChannelId,
|
||||
appName,
|
||||
"Warning",
|
||||
NotificationManager.IMPORTANCE_HIGH
|
||||
).let {
|
||||
it.description = context.getString(R.string.warning_notif_description)
|
||||
@ -110,8 +111,14 @@ object NotificationUtils {
|
||||
.setOngoing(true)
|
||||
|
||||
with(NotificationManagerCompat.from(context)) {
|
||||
if (ActivityCompat.checkSelfPermission(
|
||||
context,
|
||||
Manifest.permission.POST_NOTIFICATIONS
|
||||
) == PackageManager.PERMISSION_GRANTED
|
||||
) {
|
||||
notify(NOTIFICATION_ID_WARNING, builder.build())
|
||||
}
|
||||
}
|
||||
warningShown = true
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user