Skip to content

Commit

Permalink
Create a group for the service notification
Browse files Browse the repository at this point in the history
  • Loading branch information
greenart7c3 committed Dec 21, 2024
1 parent 1265cf7 commit 855ec3e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.koalasat.pokey.service
import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.app.Service
Expand All @@ -15,7 +14,10 @@ import android.os.Handler
import android.os.IBinder
import android.os.Looper
import android.util.Log
import androidx.core.app.NotificationChannelCompat
import androidx.core.app.NotificationChannelGroupCompat
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import com.koalasat.pokey.Connectivity
import com.koalasat.pokey.MainActivity
import com.koalasat.pokey.Pokey
Expand Down Expand Up @@ -251,12 +253,26 @@ class NotificationsService : Service() {
}

private fun createNotification(): Notification {
val notificationManager = NotificationManagerCompat.from(this)

Log.d("Pokey", "Building groups...")
val group = NotificationChannelGroupCompat.Builder("ServiceGroup")
.setName(getString(R.string.service))
.setDescription(getString(R.string.pokey_is_running_in_background))
.build()

notificationManager.createNotificationChannelGroup(group)

Log.d("Pokey", "Building channels...")
val channelRelays = NotificationChannel(channelRelaysId, getString(R.string.relays_connection), NotificationManager.IMPORTANCE_DEFAULT)
channelRelays.setSound(null, null)
val channelRelays = NotificationChannelCompat.Builder(channelRelaysId, NotificationManager.IMPORTANCE_DEFAULT)
.setName(getString(R.string.relays_connection))
.setSound(null, null)
.setGroup(group.id)
.build()

val channelNotification = NotificationChannel(channelNotificationsId, getString(R.string.configuration), NotificationManager.IMPORTANCE_HIGH)
val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
val channelNotification = NotificationChannelCompat.Builder(channelNotificationsId, NotificationManager.IMPORTANCE_HIGH)
.setName(getString(R.string.configuration))
.build()

notificationManager.createNotificationChannel(channelRelays)
notificationManager.createNotificationChannel(channelNotification)
Expand All @@ -266,6 +282,7 @@ class NotificationsService : Service() {
NotificationCompat.Builder(this, channelRelaysId)
.setContentTitle(getString(R.string.pokey_is_running_in_background))
.setPriority(NotificationCompat.PRIORITY_MIN)
.setGroup(group.id)
.setSmallIcon(R.drawable.ic_launcher_foreground)

return notificationBuilder.build()
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,5 @@
<string name="action_settings">Settings</string>
<string name="title_notifications">Notifications</string>
<string name="no_notifications">You didn\'t receive any notification yet</string>
<string name="service">Service</string>
</resources>

0 comments on commit 855ec3e

Please sign in to comment.