Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xamarin Forms - Android - Cancel and CancelAll not working. #380

Closed
minitockers opened this issue Mar 5, 2023 · 21 comments
Closed

Xamarin Forms - Android - Cancel and CancelAll not working. #380

minitockers opened this issue Mar 5, 2023 · 21 comments
Assignees
Labels
Android Android only issue bug Something isn't working Xamarin Xamarin.Forms issue

Comments

@minitockers
Copy link

minitockers commented Mar 5, 2023

I'm scheduling notifications like this:

if (await LocalNotificationCenter.Current.AreNotificationsEnabled() == false)
{
    await LocalNotificationCenter.Current.RequestNotificationPermission();
}

var notification = new NotificationRequest
{
    NotificationId = id,
    Title = title,
    Description = body,
    Schedule =
    {
        NotifyTime = time
    }
};
await LocalNotificationCenter.Current.Show(notification);

When I try to cancel any scheduled notification, with either LocalNotificationCenter.Current.Cancel(id); or LocalNotificationCenter.Current.CancelAll(); the notifications are still received.

I have to reschedule all notifications when certain things change. And this is leading to duplicate notifications.

This works perfectly on iOS.

@minitockers minitockers changed the title Android - Cancel and CancelAll not working Xamarin Forms - Android - Cancel and CancelAll not working. Mar 5, 2023
@minitockers
Copy link
Author

Anyone else having this issue on the latest version?

@Qumalu
Copy link

Qumalu commented Mar 8, 2023

Yea I'm having this issue.

@keke1210
Copy link

keke1210 commented Mar 9, 2023

I am also having this issue on .NET 7 MAUI - Android

@mbouarroudj
Copy link

I am also having this issue with MAUI project running on Android, is there a chance that this issue is fixed soon? I cannot use this plugin since the end user cannot cancel a notification, code:

var request = new NotificationRequest
{
Title = "test notif",
Description = "test notif",
NotificationId = 111,
ReturningData = "id: 111",
Schedule = new NotificationRequestSchedule
{
NotifyTime = DateTime.Now.AddSeconds(1),
NotifyRepeatInterval = TimeSpan.FromMinutes(5),
RepeatType = NotificationRepeat.TimeInterval
}

    };

    LocalNotificationCenter.Current.Show(request);

-- cancel method
LocalNotificationCenter.Current.Cancel(111)
or
LocalNotificationCenter.Current.CancelAll();

@CamilaPedocchi
Copy link

I have the same issue too.

Xamarin.Forms 5.0.0.2578
Plugin.Localnotification 10.1.4

bool resultAlerts = Plugin.LocalNotification.LocalNotificationCenter.Current.Cancel(111); - true
resultAlerts = Plugin.LocalNotification.LocalNotificationCenter.Current.CancelAll(); - true
resultAlerts = Plugin.LocalNotification.LocalNotificationCenter.Current.ClearAll(); - true

var listPending = await Plugin.LocalNotification.LocalNotificationCenter.Current.GetPendingNotificationList(); -
The list is empty, but the notification happened.

@k4p1cz
Copy link

k4p1cz commented Mar 27, 2023

Same issue! Please fix or help!

@CamilaPedocchi
Copy link

Fix the issue by installing version 10.1.3.

@k4p1cz
Copy link

k4p1cz commented Mar 27, 2023

image

I am using 10.1.4 but still no fix.

image

I've tried everyting I could.

@minitockers
Copy link
Author

Fix the issue by installing version 10.1.3.

It's working in that version for you?

@CamilaPedocchi
Copy link

Yes, it's working perfect (Android and ios), by installing version 10.1.3.

@minitockers
Copy link
Author

Yes, it's working perfect (Android and ios), by installing version 10.1.3.

It still doesn't cancel for me on 10.1.3 either!

@k4p1cz
Copy link

k4p1cz commented Mar 29, 2023

Yes, it's working perfect (Android and ios), by installing version 10.1.3.

May I see your request settings?

@CamilaPedocchi
Copy link

Xamarin.Forms 5.0.0.2578
Plugin.Localnotification 10.1.3

Xamarin.AndroidX.Core 1.9.0.2

var notificationRepeat = new NotificationRequest
{
NotificationId = notificationid,
Title = title,
Description = description,
ReturningData = idTypeGrupo + ";" + keyGroup + ";" + description,
BadgeNumber = 1,
iOS = new iOSOptions()
{
HideForegroundAlert = false,
PlayForegroundSound = true,
PresentAsBanner = true,
Priority = iOSPriority.Active,
ShowInNotificationCenter = true
},
Schedule = new NotificationRequestSchedule()
{
NotifyTime = alert
},
Android = new AndroidOptions()
{
AutoCancel = true,
ChannelId = settingApp.ChannelId,
Priority = AndroidPriority.Default,
VisibilityType = AndroidVisibilityType.Public,
LaunchAppWhenTapped = true
},
Sound = settingApp.AlertSound,
CategoryType = NotificationCategoryType.Status
};

        LocalNotificationCenter.Current.Show(notificationRepeat);

-- After ---

LocalNotificationCenter.Current.Cancel(notificationsid);

Check that Cancel is not within a task or a transaction or in any backgruond process.

@Qumalu
Copy link

Qumalu commented Mar 30, 2023

Xamarin.Forms 5.0.0.2578 Plugin.Localnotification 10.1.3

Xamarin.AndroidX.Core 1.9.0.2

var notificationRepeat = new NotificationRequest { NotificationId = notificationid, Title = title, Description = description, ReturningData = idTypeGrupo + ";" + keyGroup + ";" + description, BadgeNumber = 1, iOS = new iOSOptions() { HideForegroundAlert = false, PlayForegroundSound = true, PresentAsBanner = true, Priority = iOSPriority.Active, ShowInNotificationCenter = true }, Schedule = new NotificationRequestSchedule() { NotifyTime = alert }, Android = new AndroidOptions() { AutoCancel = true, ChannelId = settingApp.ChannelId, Priority = AndroidPriority.Default, VisibilityType = AndroidVisibilityType.Public, LaunchAppWhenTapped = true }, Sound = settingApp.AlertSound, CategoryType = NotificationCategoryType.Status };

        LocalNotificationCenter.Current.Show(notificationRepeat);

-- After ---

LocalNotificationCenter.Current.Cancel(notificationsid);

Check that Cancel is not within a task or a transaction or in any backgruond process.

How you know its canceled and not cleared, this is scheduled notification not repeating one, for me downgrading didn't do the job it clears the notification but it does not cancel it.

@k4p1cz
Copy link

k4p1cz commented Mar 30, 2023

Xamarin.Forms 5.0.0.2578 Plugin.Localnotification 10.1.3

Xamarin.AndroidX.Core 1.9.0.2

var notificationRepeat = new NotificationRequest { NotificationId = notificationid, Title = title, Description = description, ReturningData = idTypeGrupo + ";" + keyGroup + ";" + description, BadgeNumber = 1, iOS = new iOSOptions() { HideForegroundAlert = false, PlayForegroundSound = true, PresentAsBanner = true, Priority = iOSPriority.Active, ShowInNotificationCenter = true }, Schedule = new NotificationRequestSchedule() { NotifyTime = alert }, Android = new AndroidOptions() { AutoCancel = true, ChannelId = settingApp.ChannelId, Priority = AndroidPriority.Default, VisibilityType = AndroidVisibilityType.Public, LaunchAppWhenTapped = true }, Sound = settingApp.AlertSound, CategoryType = NotificationCategoryType.Status };

    LocalNotificationCenter.Current.Show(notificationRepeat);

-- After ---

LocalNotificationCenter.Current.Cancel(notificationsid);

Check that Cancel is not within a task or a transaction or in any backgruond process.

How you know its canceled and not cleared, this is scheduled notification not repeating one, for me downgrading didn't do the job it clears the notification but it does not cancel it.

Yeah. I've set my notification to be repeating every 10s just to set it up and I use Cancel() function with notification ID. It clears but it it doesn't stop the notification repeatness.

@minitockers
Copy link
Author

Xamarin.Forms 5.0.0.2578 Plugin.Localnotification 10.1.3

Xamarin.AndroidX.Core 1.9.0.2

var notificationRepeat = new NotificationRequest { NotificationId = notificationid, Title = title, Description = description, ReturningData = idTypeGrupo + ";" + keyGroup + ";" + description, BadgeNumber = 1, iOS = new iOSOptions() { HideForegroundAlert = false, PlayForegroundSound = true, PresentAsBanner = true, Priority = iOSPriority.Active, ShowInNotificationCenter = true }, Schedule = new NotificationRequestSchedule() { NotifyTime = alert }, Android = new AndroidOptions() { AutoCancel = true, ChannelId = settingApp.ChannelId, Priority = AndroidPriority.Default, VisibilityType = AndroidVisibilityType.Public, LaunchAppWhenTapped = true }, Sound = settingApp.AlertSound, CategoryType = NotificationCategoryType.Status };

        LocalNotificationCenter.Current.Show(notificationRepeat);

-- After ---

LocalNotificationCenter.Current.Cancel(notificationsid);

Check that Cancel is not within a task or a transaction or in any backgruond process.

So after more testing I realised the cancel was being called before the show, with how my threading was working.

But now I fixed that, it is also seemingly working on 10.1.4. Whereas clearly lots of people are still having issues with that, like I first raised.
Unless I'm having some strange caching issue and I'm somehow actually still using 10.1.3!

@k4p1cz
Copy link

k4p1cz commented Mar 30, 2023

Xamarin.Forms 5.0.0.2578 Plugin.Localnotification 10.1.3

Xamarin.AndroidX.Core 1.9.0.2

var notificationRepeat = new NotificationRequest { NotificationId = notificationid, Title = title, Description = description, ReturningData = idTypeGrupo + ";" + keyGroup + ";" + description, BadgeNumber = 1, iOS = new iOSOptions() { HideForegroundAlert = false, PlayForegroundSound = true, PresentAsBanner = true, Priority = iOSPriority.Active, ShowInNotificationCenter = true }, Schedule = new NotificationRequestSchedule() { NotifyTime = alert }, Android = new AndroidOptions() { AutoCancel = true, ChannelId = settingApp.ChannelId, Priority = AndroidPriority.Default, VisibilityType = AndroidVisibilityType.Public, LaunchAppWhenTapped = true }, Sound = settingApp.AlertSound, CategoryType = NotificationCategoryType.Status };

    LocalNotificationCenter.Current.Show(notificationRepeat);

-- After ---

LocalNotificationCenter.Current.Cancel(notificationsid);

Check that Cancel is not within a task or a transaction or in any backgruond process.

So after more testing I realised the cancel was being called before the show, with how my threading was working.

But now I fixed that, it is also seemingly working on 10.1.4. Whereas clearly lots of people are still having issues with that, like I first raised.

Unless I'm having some strange caching issue and I'm somehow actually still using 10.1.3!

I am calling Cancel() after button click so I have no clue and I am certain that my Cancel() function is being called after Send() function.

@minitockers
Copy link
Author

function

That's the boat I was in, so I have no idea why mine seems to be working now!

I haven't fully tested, I've just tested doing a loop to create 5 notifications 5 seconds apart. And then calling cancel on the first 2 ids, and it worked to only show the last 3 test notifications. But this previously hadn't been working.

In my real code, I'm calling CancelAll before then recreating all notifications, when the user changes what time they want the notifications. This part I haven't managed to check yet.

@k4p1cz
Copy link

k4p1cz commented Mar 30, 2023

function

That's the boat I was in, so I have no idea why mine seems to be working now!

I haven't fully tested, I've just tested doing a loop to create 5 notifications 5 seconds apart. And then calling cancel on the first 2 ids, and it worked to only show the last 3 test notifications. But this previously hadn't been working.

In my real code, I'm calling CancelAll before then recreating all notifications, when the user changes what time they want the notifications. This part I haven't managed to check yet.

May I message you so we can have a chat about that? I really need to find a way to fix this issue.

@thudugala thudugala self-assigned this May 19, 2023
@thudugala thudugala added Android Android only issue Xamarin Xamarin.Forms issue labels May 19, 2023
@thudugala
Copy link
Owner

@minitockers Please try Version 10.1.5

cc @CamilaPedocchi @keke1210 @mbouarroudj

FYI v10.1.5 has a breaking change Android permission must be specified at the application level now.

@thudugala thudugala added the bug Something isn't working label May 20, 2023
@CamilaPedocchi
Copy link

Version 10.1.5 works. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Android Android only issue bug Something isn't working Xamarin Xamarin.Forms issue
Projects
None yet
Development

No branches or pull requests

7 participants