Delete os notification channel when unused
When deleting local channel from the UI
This commit is contained in:
parent
19ab14305f
commit
077e117e10
|
@ -1,6 +1,9 @@
|
|||
package org.unifiedpush.distributor.nextpush
|
||||
|
||||
import android.app.NotificationManager
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import androidx.annotation.RequiresApi
|
||||
import java.util.UUID
|
||||
import org.unifiedpush.distributor.nextpush.Database.Companion.getDb
|
||||
import org.unifiedpush.distributor.nextpush.api.Api
|
||||
|
@ -20,4 +23,20 @@ object LocalNotification {
|
|||
val title = getDb(context).getNotificationTitle(connectorToken) ?: context.getString(R.string.app_name)
|
||||
FromPushNotification(context, title, content).showBig()
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the notification channel registered to the OS
|
||||
*/
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
fun removeOsNotificationChannel(context: Context, connectorToken: String) {
|
||||
val title = getDb(context).getNotificationTitle(connectorToken) ?: return
|
||||
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
notificationManager.deleteNotificationChannel(
|
||||
getNotificationChannelId(context, title)
|
||||
)
|
||||
}
|
||||
|
||||
fun getNotificationChannelId(context: Context, title: String): String {
|
||||
return "${context.getString(R.string.app_name)}.Push.$title"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.unifiedpush.distributor.nextpush.distributor
|
|||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.util.Log
|
||||
import org.unifiedpush.distributor.nextpush.Database
|
||||
import org.unifiedpush.distributor.nextpush.Database.Companion.getDb
|
||||
|
@ -61,9 +62,20 @@ object Distributor {
|
|||
context.sendBroadcast(broadcastIntent)
|
||||
}
|
||||
|
||||
/**
|
||||
* Send UNREGISTERED action.
|
||||
*
|
||||
* If this is for a local application: we remove the notification channel instead
|
||||
*/
|
||||
private fun sendUnregistered(context: Context, connectorToken: String) {
|
||||
val application = getApp(context, connectorToken)
|
||||
if (application.isNullOrBlank()) {
|
||||
val application = getApp(context, connectorToken) ?: return
|
||||
if (application == context.packageName) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
LocalNotification.removeOsNotificationChannel(
|
||||
context,
|
||||
connectorToken
|
||||
)
|
||||
}
|
||||
return
|
||||
}
|
||||
val broadcastIntent = Intent()
|
||||
|
|
|
@ -14,6 +14,7 @@ import androidx.core.app.ActivityCompat
|
|||
import androidx.core.app.NotificationManagerCompat
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
import org.unifiedpush.distributor.nextpush.LocalNotification
|
||||
import org.unifiedpush.distributor.nextpush.R
|
||||
import org.unifiedpush.distributor.nextpush.activities.MainActivity
|
||||
import org.unifiedpush.distributor.nextpush.services.RegistrationCountCache
|
||||
|
@ -280,8 +281,8 @@ class FromPushNotification(context: Context, title: String, content: String) : A
|
|||
false
|
||||
),
|
||||
ChannelData(
|
||||
"${context.getString(R.string.app_name)}.Push.$title",
|
||||
"(Push) $title",
|
||||
LocalNotification.getNotificationChannelId(context, title),
|
||||
context.getString(R.string.list_registrations_local_title, title),
|
||||
NotificationManager.IMPORTANCE_HIGH,
|
||||
context.getString(R.string.list_registrations_local_description)
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue