diff --git a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt index f4359cbc0..4ddb1845a 100644 --- a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt +++ b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt @@ -340,7 +340,8 @@ class MeshService : Service(), Logging { serviceNotifications.updateMessageNotification( contactKey, getSenderName(dataPacket), - message + message, + isBroadcast = dataPacket.to == DataPacket.ID_BROADCAST ) } diff --git a/app/src/main/java/com/geeksville/mesh/service/MeshServiceNotifications.kt b/app/src/main/java/com/geeksville/mesh/service/MeshServiceNotifications.kt index 60c51731c..862d0b764 100644 --- a/app/src/main/java/com/geeksville/mesh/service/MeshServiceNotifications.kt +++ b/app/src/main/java/com/geeksville/mesh/service/MeshServiceNotifications.kt @@ -66,6 +66,7 @@ class MeshServiceNotifications( if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { createNotificationChannel() createMessageNotificationChannel() + createBroadcastNotificationChannel() createAlertNotificationChannel() createNewNodeNotificationChannel() createLowBatteryNotificationChannel() @@ -118,6 +119,32 @@ class MeshServiceNotifications( return channelId } + @RequiresApi(Build.VERSION_CODES.O) + private fun createBroadcastNotificationChannel(): String { + val channelId = "my_broadcasts" + if (notificationManager.getNotificationChannel(channelId) == null) { + val channelName = context.getString(R.string.meshtastic_broadcast_notifications) + val channel = NotificationChannel( + channelId, + channelName, + NotificationManager.IMPORTANCE_DEFAULT + ).apply { + lightColor = notificationLightColor + lockscreenVisibility = Notification.VISIBILITY_PUBLIC + setShowBadge(true) + setSound( + RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION), + AudioAttributes.Builder() + .setUsage(AudioAttributes.USAGE_NOTIFICATION) + .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) + .build() + ) + } + notificationManager.createNotificationChannel(channel) + } + return channelId + } + @RequiresApi(Build.VERSION_CODES.O) private fun createAlertNotificationChannel(): String { val channelId = "my_alerts" @@ -274,6 +301,14 @@ class MeshServiceNotifications( } } + private val broadcastChannelId: String by lazy { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + createBroadcastNotificationChannel() + } else { + "" + } + } + private val alertChannelId: String by lazy { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { createAlertNotificationChannel() @@ -349,10 +384,10 @@ class MeshServiceNotifications( notificationManager.cancel(contactKey.hashCode()) } - fun updateMessageNotification(contactKey: String, name: String, message: String) = + fun updateMessageNotification(contactKey: String, name: String, message: String, isBroadcast: Boolean) = notificationManager.notify( contactKey.hashCode(), // show unique notifications, - createMessageNotification(contactKey, name, message) + createMessageNotification(contactKey, name, message, isBroadcast) ) fun showAlertNotification(contactKey: String, name: String, alert: String) { @@ -486,10 +521,12 @@ class MeshServiceNotifications( private fun createMessageNotification( contactKey: String, name: String, - message: String + message: String, + isBroadcast: Boolean, ): Notification { + val channelId = if (isBroadcast) broadcastChannelId else messageChannelId val messageNotificationBuilder: NotificationCompat.Builder = - commonBuilder(messageChannelId, createOpenMessageIntent(contactKey)) + commonBuilder(channelId, createOpenMessageIntent(contactKey)) val person = Person.Builder().setName(name).build() // Key for the string that's delivered in the action's intent. diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fa7875796..2a97396a0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -175,7 +175,8 @@ message reception time message reception state Message delivery status - Message notifications + Direct message notifications + Broadcast message notifications Alert notifications Protocol stress test Firmware update required.