Skip to content

"PendingIntent must be mutable" error using Geofencing #541

Description

@RQISystems

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions