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