Issue with Azure Push Notifications on Xamarin Android - PendingIntent Error
I've implemented push notifications for my Xamarin application, and everything works smoothly on iOS. However, when the Android application is put in the background or closed, notifications fail to reach the device, and an error is encountered:
Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent. Strongly consider using FLAG_IMMUTABLE; only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g., 'if it needs to be used with inline replies or bubbles.'
My app's version is 33, Microsoft.Azure.NotificationHubs version is 4.1.0, and Xamarin.Forms version is 5.0.0.2337. Here's a snippet of my code:
public void OnPushNotificationReceived(Context context, INotificationMessage message)
{
Intent intent = new Intent(AndroidApp.Context, typeof(MainActivity));
intent.PutExtra(TitleKey, message.Title);
intent.PutExtra(MessageKey, message.Body);
PendingIntent pendingIntent = PendingIntent.GetActivity(AndroidApp.Context, pendingIntentId++, intent, PendingIntentFlags.Immutable);
NotificationCompat.Builder builder = new NotificationCompat.Builder(AndroidApp.Context, channelId)
.SetContentIntent(pendingIntent)
.SetContentTitle(message.Title)
.SetContentText(message.Body)
.SetLargeIcon(BitmapFactory.DecodeResource(AndroidApp.Context.Resources, Resource.Drawable.abc_btn_check_material))
.SetSmallIcon(Resource.Drawable.ateshgah_loading)
.SetDefaults((int)NotificationDefaults.Sound | (int)NotificationDefaults.Vibrate)
.SetPriority(NotificationCompat.PriorityHigh);
builder.SetFullScreenIntent(pendingIntent, true);
Notification notification = builder.Build();
manager.Notify(messageId++, notification);
}
I would appreciate any insights or suggestions on resolving this issue.