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 18, 2024
1 parent fbeec5f commit be2e63f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package com.greenart7c3.nostrsigner.service

import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.Service
import android.content.Context
import android.content.Intent
import android.net.ConnectivityManager
import android.net.Network
import android.net.NetworkCapabilities
import android.os.IBinder
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.greenart7c3.nostrsigner.BuildConfig
import com.greenart7c3.nostrsigner.NostrSigner
import com.greenart7c3.nostrsigner.R
Expand Down Expand Up @@ -95,13 +96,24 @@ class ConnectivityService : Service() {

private fun createNotification(): Notification {
val channelId = "ServiceChannel"
val channel = NotificationChannel(channelId, getString(R.string.checking_connectivity), NotificationManager.IMPORTANCE_DEFAULT)
channel.setSound(null, null)
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val group = NotificationChannelGroupCompat.Builder("ServiceGroup")
.setName(getString(R.string.service))
.setDescription(getString(R.string.service_description))
.build()
val channel = NotificationChannelCompat.Builder(channelId, NotificationManager.IMPORTANCE_DEFAULT)
.setName(getString(R.string.service))
.setDescription(getString(R.string.amber_is_running_in_background))
.setSound(null, null)
.setGroup(group.id)
.build()

val notificationManager = NotificationManagerCompat.from(this)
notificationManager.createNotificationChannelGroup(group)
notificationManager.createNotificationChannel(channel)

val notificationBuilder =
NotificationCompat.Builder(this, channelId)
.setGroup(group.id)
.setContentTitle(getString(R.string.amber_is_running_in_background))
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setSmallIcon(R.drawable.ic_notification)
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -465,4 +465,6 @@
<string name="congratulations_your_new_account_is_ready">Congratulations, your new account is ready!\n</string>
<string name="your_account_is_ready_to_use">Now you can start using apps that support Amber, when needed Amber will open and ask you to confirm permissions.\nIn this view you will find all the apps that have active permissions.\n\nDiscover all Nostr apps for android at </string>
<string name="nostr_app">nostrapps.com</string>
<string name="service">Service</string>
<string name="service_description">Service background notification</string>
</resources>

0 comments on commit be2e63f

Please sign in to comment.