From 1f44ebc3a8f8e47be0cd34616e1065f80edec5de Mon Sep 17 00:00:00 2001 From: JasperEssien2 Date: Thu, 7 Jul 2022 10:09:41 +0100 Subject: [PATCH] Fixed bug that causes alarm to ring partially during screen lock --- .../kotlin/com/dexloop/flutter_alarm_notification/Utils.kt | 5 ++++- lib/flutter_alarm_notification.dart | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/android/src/main/kotlin/com/dexloop/flutter_alarm_notification/Utils.kt b/android/src/main/kotlin/com/dexloop/flutter_alarm_notification/Utils.kt index 6137753..d8a368c 100644 --- a/android/src/main/kotlin/com/dexloop/flutter_alarm_notification/Utils.kt +++ b/android/src/main/kotlin/com/dexloop/flutter_alarm_notification/Utils.kt @@ -35,6 +35,7 @@ import android.content.pm.PackageManager import android.graphics.Color import android.graphics.drawable.BitmapDrawable import android.media.AudioAttributes +import android.media.AudioManager import android.media.RingtoneManager import android.net.Uri import android.os.Build @@ -64,7 +65,7 @@ fun Context.showNotification( longArrayOf( 0, 100, 200, 300 ) - ).setSilent(false).setOnlyAlertOnce(true) + ).setSilent(false) .setFullScreenIntent( pendingIntent( requestCode = 35, @@ -130,10 +131,12 @@ private fun NotificationManager.buildChannel( } channel.enableLights(true) + val notificationSound: Uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM) val audioAttributes = AudioAttributes.Builder() .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) .setUsage(AudioAttributes.USAGE_ALARM) + .setLegacyStreamType(AudioManager.STREAM_ALARM) .build() channel.setSound(notificationSound, audioAttributes) diff --git a/lib/flutter_alarm_notification.dart b/lib/flutter_alarm_notification.dart index 12d719b..96ec6b3 100644 --- a/lib/flutter_alarm_notification.dart +++ b/lib/flutter_alarm_notification.dart @@ -27,7 +27,9 @@ class FlutterAlarmNotification { static registerPort({NotificationActionCallback? callback}) { IsolateNameServer.registerPortWithName( - _uiReceivePort.sendPort, _buttonActionIsolateName); + _uiReceivePort.sendPort, + _buttonActionIsolateName, + ); if (callback != null) { listenable.listen((message) { @@ -64,7 +66,7 @@ class FlutterAlarmNotification { /// Set a recursive alarms that sets of at a particular time /// and repeats at an interval /// To set configurations for this alram use [alarmConfig] - /// [nottificationBuilder] accepts fields that's pertaining to the notification + /// [notificationBuilder] accepts fields that's pertaining to the notification /// if you need to pass data to the intent set [intentBuilder] parameter . static Future registerRepeatingAlarm({ required AlarmConfig alarmConfig,