Skip to content

Commit

Permalink
Fix android notif
Browse files Browse the repository at this point in the history
  • Loading branch information
gdelataillade committed Dec 11, 2023
1 parent cb0ddc8 commit 75ad7eb
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand All @@ -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
Expand All @@ -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(
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion example/lib/screens/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class _ExampleAlarmHomeScreenState extends State<ExampleAlarmHomeScreen> {
@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(
Expand Down
6 changes: 3 additions & 3 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions ios/Classes/SwiftAlarmPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

8 comments on commit 75ad7eb

@theDeveloper574
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello there i'm tying to implement wake the app using flutter foreground services
tying to launch the app when alarm start ringing
but cant find any solution app is wakes up but it calls the home screen
android:showWhenLocked="true"
android:turnScreenOn="true"
these are the activities i have done.
App is launched.
FlutterForegroundTask.launchApp('/second');
but cant get this how to call this method.

thank you.

@gdelataillade
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @theDeveloper574

Thanks for your interest in the plugin.

Have you tried to use the androidFullScreenIntent parameter ?

Note that this commit is from the development phase of version 3.0.0 so it's not fully ready, I still have issues with Android 13.

@theDeveloper574
Copy link

@theDeveloper574 theDeveloper574 commented on 75ad7eb Dec 14, 2023 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gdelataillade
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You want to show a specific screen when alarm rings foreground or terminated state ?
Take a look at the example app, it's what I do, I launch with ExampleAlarmRingScreen.

@theDeveloper574
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok I'll check.

@theDeveloper574
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you provide me link of example app?

@gdelataillade
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@theDeveloper574
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay thank you bro think i got the solution.
checked the code it's work fine.

Appreciated Good Work ❤️

Please sign in to comment.