From 75ad7eb9b8bebf2c08d8f2ad6218383bc39ee2f9 Mon Sep 17 00:00:00 2001 From: Gautier de Lataillade <32983806+gdelataillade@users.noreply.github.com> Date: Mon, 11 Dec 2023 19:55:40 +0100 Subject: [PATCH] Fix android notif --- CHANGELOG.md | 3 +++ .../alarm/services/NotificationOnKillService.kt | 2 +- .../alarm/services/NotificationService.kt | 10 ++++------ example/lib/screens/home.dart | 2 +- example/pubspec.lock | 6 +++--- ios/Classes/SwiftAlarmPlugin.swift | 4 ++-- pubspec.yaml | 2 +- 7 files changed, 15 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 847eb7b9..77050fbc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 3.0.0-dev.7 +* [Android] Fix notification delay and sound. + ## 3.0.0-dev.6 * [Android] Fix alarms for Android API 31 and above. * [iOS] Fix audio player fade duration. diff --git a/android/src/main/kotlin/com/gdelataillade/alarm/services/NotificationOnKillService.kt b/android/src/main/kotlin/com/gdelataillade/alarm/services/NotificationOnKillService.kt index e50b8201..9157255c 100644 --- a/android/src/main/kotlin/com/gdelataillade/alarm/services/NotificationOnKillService.kt +++ b/android/src/main/kotlin/com/gdelataillade/alarm/services/NotificationOnKillService.kt @@ -44,7 +44,7 @@ class NotificationOnKillService: Service() { val name = "Alarm notification service on application kill" val descriptionText = "If an alarm was set and the app is killed, a notification will show to warn the user the alarm could not ring as long as the app is killed" - val importance = NotificationManager.IMPORTANCE_MAX + val importance = NotificationManager.IMPORTANCE_HIGH val channel = NotificationChannel(CHANNEL_ID, name, importance).apply { body = descriptionText } diff --git a/android/src/main/kotlin/com/gdelataillade/alarm/services/NotificationService.kt b/android/src/main/kotlin/com/gdelataillade/alarm/services/NotificationService.kt index 3e117108..f97643c0 100644 --- a/android/src/main/kotlin/com/gdelataillade/alarm/services/NotificationService.kt +++ b/android/src/main/kotlin/com/gdelataillade/alarm/services/NotificationService.kt @@ -13,7 +13,7 @@ import androidx.core.app.NotificationCompat class NotificationHandler(private val context: Context) { companion object { - private const val CHANNEL_ID = "alarm_service_channel" + private const val CHANNEL_ID = "alarm_plugin_channel" private const val CHANNEL_NAME = "Alarm Notification" } @@ -23,13 +23,12 @@ class NotificationHandler(private val context: Context) { private fun createNotificationChannel() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - val soundUri = Uri.parse("android.resource://${context.packageName}/${R.raw.blank}") val channel = NotificationChannel( CHANNEL_ID, CHANNEL_NAME, - NotificationManager.IMPORTANCE_MAX + NotificationManager.IMPORTANCE_HIGH ).apply { - setSound(soundUri, AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION).setUsage(AudioAttributes.USAGE_NOTIFICATION).build()) + setSound(null, null) } val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager @@ -40,7 +39,6 @@ class NotificationHandler(private val context: Context) { fun buildNotification(title: String, body: String, fullScreen: Boolean, pendingIntent: PendingIntent): Notification { val iconResId = context.resources.getIdentifier("ic_launcher", "mipmap", context.packageName) - val soundUri = Uri.parse("android.resource://${context.packageName}/${R.raw.blank}") val intent = context.packageManager.getLaunchIntentForPackage(context.packageName) val pendingIntent = PendingIntent.getActivity( @@ -59,7 +57,7 @@ class NotificationHandler(private val context: Context) { .setAutoCancel(false) .setOngoing(true) .setContentIntent(pendingIntent) - .setSound(soundUri) + .setSound(null) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) if (fullScreen) { diff --git a/example/lib/screens/home.dart b/example/lib/screens/home.dart index bb51297e..ddf4d5d0 100644 --- a/example/lib/screens/home.dart +++ b/example/lib/screens/home.dart @@ -71,7 +71,7 @@ class _ExampleAlarmHomeScreenState extends State { @override Widget build(BuildContext context) { return Scaffold( - appBar: AppBar(title: const Text('alarm 3.0.0-dev.6')), + appBar: AppBar(title: const Text('alarm 3.0.0-dev.7')), body: SafeArea( child: alarms.isNotEmpty ? ListView.separated( diff --git a/example/pubspec.lock b/example/pubspec.lock index 880603d7..f36859e0 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,7 +7,7 @@ packages: path: ".." relative: true source: path - version: "3.0.0-dev.6" + version: "3.0.0-dev.7" async: dependency: transitive description: @@ -320,10 +320,10 @@ packages: dependency: transitive description: name: win32 - sha256: "7c99c0e1e2fa190b48d25c81ca5e42036d5cac81430ef249027d97b0935c553f" + sha256: b0f37db61ba2f2e9b7a78a1caece0052564d1bc70668156cf3a29d676fe4e574 url: "https://pub.dev" source: hosted - version: "5.1.0" + version: "5.1.1" xdg_directories: dependency: transitive description: diff --git a/ios/Classes/SwiftAlarmPlugin.swift b/ios/Classes/SwiftAlarmPlugin.swift index 57696a89..c5a1a9a2 100644 --- a/ios/Classes/SwiftAlarmPlugin.swift +++ b/ios/Classes/SwiftAlarmPlugin.swift @@ -153,7 +153,7 @@ public class SwiftAlarmPlugin: NSObject, FlutterPlugin { self.startSilentSound() } - audioPlayer.play(atTime: time) + audioPlayer.play(atTime: time + 0.5) self.tasksQueue[id] = DispatchWorkItem(block: { self.handleAlarmAfterDelay( @@ -317,7 +317,7 @@ public class SwiftAlarmPlugin: NSObject, FlutterPlugin { DispatchQueue.main.async { let volumeView = MPVolumeView() - DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.5) { + DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.1) { if let slider = volumeView.subviews.first(where: { $0 is UISlider }) as? UISlider { self.previousVolume = enable ? slider.value : nil slider.value = volume diff --git a/pubspec.yaml b/pubspec.yaml index 2c2eb7a8..7c416a4c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: alarm description: A simple Flutter alarm manager plugin for both iOS and Android. -version: 3.0.0-dev.6 +version: 3.0.0-dev.7 homepage: https://github.com/gdelataillade/alarm environment: