Open ClauderGunpowder opened 1 year ago
I'm not convinced it's a problem with the plugin as much as it is a problem with Android. I went through the trouble of creating my own BroadcastReceiver in Xamarin.Android and registering my geofences manually, then using the plugin to send notifications, and the behavior didn't really change.
What fixed it for me was doing everything I could to get more timely location updates. For example, after adding activity tracking, then every time I get into or out of the car, an activity monitoring service fires up and gets location, and that tells the device it's in a geofence. Now notifications deliver like they should. Or at least closer to what I expect.
Android background location was brutally bad. It's improved a lot with Android 13. Combining it with other services like activity tracking helps a ton.
That's very interesting because I have experienced that if I later fire a method getting my current location, a couple of apparently stacked up but invisible notifications suddenly shows up as visible notifications on the phone.
Exactly, because the phone finally got the location and delivered the scheduled notifications.
But still, I'm getting doubts about using this for my current project. Have praised that everything worked on iPhone (14 v/iOS 16). Then earlier today taking it on the road on my iPhone Pro 11, and no notifications at all. Okay, back to my desktop, creating and testing with an iPhone Pro 11 emulator and Nothing! Testing again on iPhone 14 and Bingo, that works. Can't have it working on only a small number of devices though, so ... (Permissions match on the iPhone 11 and iPhone 14 emulators)
@thudugala Notification w/Geofence setup: Do you need to create that in a foreground service or do the plugin manage that itself? For iOS testing, I just test with code in a .maui MainPage.xaml.cs sample project. Expecting Android to behave the same way.
Describe the bug Cannot get Geofence notifications to execute on Android.
Notice:
I suspected that for my Android version I needed to add a channel group and channel, but when I do I get this error message at startup (see below) so therefore these two lines is commented out in the code sample:
JNINativeWrapper.g.cs : NotificationChannelGroup doesn't exist
To Reproduce Steps to reproduce the behavior: MauiProgram
using Microsoft.Extensions.Logging; using Plugin.LocalNotification; using Plugin.LocalNotification.AndroidOption; using Plugin.LocalNotification.iOSOption;
namespace PowerFences;
public static class MauiProgram { public static MauiApp CreateMauiApp() { NotificationChannelGroupRequest notificationChannelGroupRequest = new Plugin.LocalNotification.AndroidOption.NotificationChannelGroupRequest() { Group = "PowerFences", Name = "PowerFences" }; NotificationChannelRequest notificationChannelRequest = new Plugin.LocalNotification.AndroidOption.NotificationChannelRequest() { Name = "PowerFences", Description = "Channel for Android notifications", Group = "PowerFences", ShowBadge = true, EnableSound = true };
if DEBUG
endif
}
The NotificationRequest w/Geofence:
public void addGeofenceNotificationHandler(int notificationId, NotificationRequestGeofence.GeofenceNotifyOn direction) { var notification = new NotificationRequest { NotificationId = notificationId, Title = "PowerFence", Subtitle = direction == NotificationRequestGeofence.GeofenceNotifyOn.OnEntry ? "Entry" : "Exit", Description = $"Elme Alle", BadgeNumber = 2, Silent = false, iOS = new Plugin.LocalNotification.iOSOption.iOSOptions { PlayForegroundSound = true }, Android = new Plugin.LocalNotification.AndroidOption.AndroidOptions { LaunchAppWhenTapped = true, ChannelId = "PowerFences" }, Group = "PowerFences", CategoryType = NotificationCategoryType.Reminder, ReturningData = direction == NotificationRequestGeofence.GeofenceNotifyOn.OnEntry ? "Entry" : "Exit", Geofence = new NotificationRequestGeofence { Center = new NotificationRequestGeofence.Position { Latitude = _savedLocation.Latitude, Longitude = _savedLocation.Longitude }, RadiusInMeters = 1000, NotifyOn = direction, iOS = new Plugin.LocalNotification.iOSOption.iOSGeofenceOptions { Repeats = true }, Android = new Plugin.LocalNotification.AndroidOption.AndroidGeofenceOptions { ExpirationDurationInMilliseconds = -1, LoiteringDelayMilliseconds = 1000, ResponsivenessMilliseconds = 0 } } };
Expected behavior I expect a notification to appear whenever I enter or exit a defined geofence area.
Platform (please complete the following information):
Smartphone (please complete the following information):
Additional context Using Visual Studio 2022 for Mac .NET 7, MAUI
Required permissions set for Android: AcceptBackgroundLocation, Access CoarseLocation, AccessFineLocation, AccessNetworkState, Internet, LocationHardware, PostNotifications. info.plist properties set for iOS: Privacy - Location Always and When In Use Usage Description (true), Privacy - Reminders Usage Description (true), Required background modes.