Forces the creation of Notification Channels to see if they show up on Samsung phones.
This commit is contained in:
+2
-2
@@ -21,7 +21,7 @@ object NotificationUtils {
|
|||||||
private const val DM_GROUP_KEY = "com.vitorpamplona.amethyst.DM_NOTIFICATION"
|
private const val DM_GROUP_KEY = "com.vitorpamplona.amethyst.DM_NOTIFICATION"
|
||||||
private const val ZAP_GROUP_KEY = "com.vitorpamplona.amethyst.ZAP_NOTIFICATION"
|
private const val ZAP_GROUP_KEY = "com.vitorpamplona.amethyst.ZAP_NOTIFICATION"
|
||||||
|
|
||||||
private fun getOrCreateDMChannel(applicationContext: Context): NotificationChannel {
|
fun NotificationManager.getOrCreateDMChannel(applicationContext: Context): NotificationChannel {
|
||||||
if (dmChannel != null) return dmChannel!!
|
if (dmChannel != null) return dmChannel!!
|
||||||
|
|
||||||
dmChannel = NotificationChannel(
|
dmChannel = NotificationChannel(
|
||||||
@@ -41,7 +41,7 @@ object NotificationUtils {
|
|||||||
return dmChannel!!
|
return dmChannel!!
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getOrCreateZapChannel(applicationContext: Context): NotificationChannel {
|
fun NotificationManager.getOrCreateZapChannel(applicationContext: Context): NotificationChannel {
|
||||||
if (zapChannel != null) return zapChannel!!
|
if (zapChannel != null) return zapChannel!!
|
||||||
|
|
||||||
zapChannel = NotificationChannel(
|
zapChannel = NotificationChannel(
|
||||||
|
|||||||
+11
-1
@@ -1,9 +1,13 @@
|
|||||||
package com.vitorpamplona.amethyst.service.notifications
|
package com.vitorpamplona.amethyst.service.notifications
|
||||||
|
|
||||||
|
import android.app.NotificationManager
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
import com.google.firebase.messaging.FirebaseMessagingService
|
import com.google.firebase.messaging.FirebaseMessagingService
|
||||||
import com.google.firebase.messaging.RemoteMessage
|
import com.google.firebase.messaging.RemoteMessage
|
||||||
import com.vitorpamplona.amethyst.LocalPreferences
|
import com.vitorpamplona.amethyst.LocalPreferences
|
||||||
import com.vitorpamplona.amethyst.service.model.Event
|
import com.vitorpamplona.amethyst.service.model.Event
|
||||||
|
import com.vitorpamplona.amethyst.service.notifications.NotificationUtils.getOrCreateDMChannel
|
||||||
|
import com.vitorpamplona.amethyst.service.notifications.NotificationUtils.getOrCreateZapChannel
|
||||||
|
|
||||||
class PushNotificationReceiverService : FirebaseMessagingService() {
|
class PushNotificationReceiverService : FirebaseMessagingService() {
|
||||||
|
|
||||||
@@ -12,11 +16,17 @@ class PushNotificationReceiverService : FirebaseMessagingService() {
|
|||||||
remoteMessage.data.let {
|
remoteMessage.data.let {
|
||||||
val eventStr = remoteMessage.data["event"] ?: return
|
val eventStr = remoteMessage.data["event"] ?: return
|
||||||
val event = Event.fromJson(eventStr, true)
|
val event = Event.fromJson(eventStr, true)
|
||||||
EventNotificationConsumer(applicationContext).unwrapAndConsume(event)
|
EventNotificationConsumer(applicationContext).consume(event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onNewToken(token: String) {
|
override fun onNewToken(token: String) {
|
||||||
RegisterAccounts(LocalPreferences.allSavedAccounts()).go(token)
|
RegisterAccounts(LocalPreferences.allSavedAccounts()).go(token)
|
||||||
|
notificationManager().getOrCreateZapChannel(applicationContext)
|
||||||
|
notificationManager().getOrCreateDMChannel(applicationContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun notificationManager(): NotificationManager {
|
||||||
|
return ContextCompat.getSystemService(applicationContext, NotificationManager::class.java) as NotificationManager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user