thudugala / thudugala/Plugin.LocalNotification
"PendingIntent must be mutable" error using Geofencing
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 474
- Forks
- 73
- PR merge metrics
- No merged PRs in 30d
Description
I have created a .NET MAUI 10 App that uses geofencing to allow users to verify if a location is valid and to add reviews using Actions. When I add .UseLocalNotificationGeofence to MauiProgram.cs, I get the following error: "10: PendingIntent must be mutable". If I remove the line from MauiProgram, i do not get the error. Here is the JavaException:
"com.google.android.gms.common.api.ApiException: 10: PendingIntent must be mutable
at com.google.android.gms.common.internal.ApiExceptionUtil.fromStatus(com.google.android.gms:play-services-base@@18.7.2:3)
at com.google.android.gms.common.api.internal.TaskUtil.setResultOrApiException(com.google.android.gms:play-services-base@@18.7.2:5)
at com.google.android.gms.internal.location.zzdj.onResult(com.google.android.gms:play-services-location@@21.2.0:1)
at com.google.android.gms.common.api.internal.IStatusCallback$Stub.zaa(com.google.android.gms:play-services-base@@18.7.2:3)
at com.google.android.gms.internal.base.zab.onTransact(com.google.android.gms:play-services-base@@18.7.2:3)
at android.os.Binder.execTransactInternal(Binder.java:1426)
at android.os.Binder.execTransact(Binder.java:1365)"
I am creating the NotificationRequests based on a collection of Locations that the user has requested. Here is my MauiProgram.cs code:
.UseLocalNotification(config =>
{
config.AddCategory(new NotificationCategory(NotificationCategoryType.Status)
{
ActionList =
[
new(100)
{
Title = "Yes",
Android =
{
LaunchAppWhenTapped = false,
IconName =
{
ResourceName = "launcher_40"
}
},
Apple =
{
Action = Plugin.LocalNotification.Core.Models.AppleOption.AppleActionType.Foreground
}
},
new(101)
{
Title = "No",
Android =
{
LaunchAppWhenTapped = false,
IconName =
{
ResourceName = "launcher_40"
}
},
Apple =
{
Action = Plugin.LocalNotification.Core.Models.AppleOption.AppleActionType.Foreground
}
},
new(102)
{
Title = "Add Review",
Android =
{
IconName = { ResourceName = "add.png" },
LaunchAppWhenTapped = true
},
Apple =
{
Action = Plugin.LocalNotification.Core.Models.AppleOption.AppleActionType.Foreground
}
}
]
})
.AddAndroid(android =>
{
android.AddChannel(new AndroidNotificationChannelRequest
{
Id = "",
Name = "",
Description = "",
Importance = AndroidImportance.High,
Sound = "rimshot"
});
})
.AddiOS(iOS =>
{
#if IOS
//iOS.SetCustomUserNotificationCenterDelegate(new CustomUserNotificationCenterDelegate());
#endif
});
})
.UseLocalNotificationGeofence();
My NotificationRequest code is:
var notification = new NotificationRequest
{
NotificationId = Convert.ToInt32(sight.SightInGeofence.Id),
Image = { ResourceName = "launcher_40" },
Title = "Sight Nearby!",
Subtitle = "Is the Sight still there?",
Description = "Click the Add Review button.",
CategoryType = NotificationCategoryType.Status,
Android =
{
ChannelId = "",
Priority = AndroidPriority.High,
TimeoutAfter = TimeSpan.FromHours(1),
OnlyAlertOnce = true,
IconSmallName = { ResourceName = "launcher_40" },
IconLargeName = { ResourceName = "launcher_40" },
},
Apple =
{
ShowInNotificationCenter = true,
}
};
notification.Geofence = new NotificationRequestGeofence
{
Center = new NotificationRequestGeofence.Position
{
Latitude = Convert.ToDouble(sight.SightInGeofence.Location_Latitude),
Longitude = Convert.ToDouble(sight.SightInGeofence.Location_Longitude),
},
RadiusInMeters = 30,
NotifyOn = NotificationRequestGeofence.GeofenceNotifyOn.OnEntry | NotificationRequestGeofence.GeofenceNotifyOn.OnExit,
};
Also, my notifications are not showing the Action buttons. I assume it is related to the issue above.
Thanks in advance for your help.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the UseLocalNotificationGeofence registration in MauiProgram.cs and trace how the NotificationRequest geofence creates its Android PendingIntent. Reproduce the geofencing error with the shown request, then verify that the PendingIntent satisfies Android's mutability requirement and that the configured Status category actions appear in the notification.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, csharp
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100