From df0822490d837b268a1299e425c9e6f38fc76e2d Mon Sep 17 00:00:00 2001 From: William Newman <3382274+newmanw@users.noreply.github.com> Date: Mon, 1 Apr 2024 12:28:41 -0600 Subject: [PATCH] Add PendingIntent.FLAG_IMMUTABLE to observation notification * Required for Android sdk 23 --- .../ObservationNotificationListener.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/mage/src/main/java/mil/nga/giat/mage/observation/ObservationNotificationListener.java b/mage/src/main/java/mil/nga/giat/mage/observation/ObservationNotificationListener.java index 56cc98b4..1579c54d 100644 --- a/mage/src/main/java/mil/nga/giat/mage/observation/ObservationNotificationListener.java +++ b/mage/src/main/java/mil/nga/giat/mage/observation/ObservationNotificationListener.java @@ -23,8 +23,8 @@ public class ObservationNotificationListener implements IObservationEventListener { public static int OBSERVATION_NOTIFICATION_ID = 1415; - private Context mContext; - private SharedPreferences mPreferences; + private final Context context; + private final SharedPreferences preferences; /** * Constructor. @@ -33,8 +33,8 @@ public class ObservationNotificationListener implements IObservationEventListene * notifications. */ public ObservationNotificationListener(Context context) { - mContext = context; - mPreferences = PreferenceManager.getDefaultSharedPreferences(mContext); + this.context = context; + preferences = PreferenceManager.getDefaultSharedPreferences(this.context); } @Override @@ -42,11 +42,11 @@ public void onObservationCreated(Collection observations, Boolean s if(sendNotifications != null && sendNotifications) { // are we configured to fire notifications? - Boolean notificationsEnabled = mPreferences.getBoolean(mContext.getString(R.string.notificationsEnabledKey), mContext.getResources().getBoolean(R.bool.notificationsEnabledDefaultValue)); + boolean notificationsEnabled = preferences.getBoolean(context.getString(R.string.notificationsEnabledKey), context.getResources().getBoolean(R.bool.notificationsEnabledDefaultValue)); // are any of the observations remote? We don't want to fire on locally created // observations. - Boolean remoteObservations = Boolean.FALSE; + boolean remoteObservations = Boolean.FALSE; if (notificationsEnabled) { for (Observation obs : observations) { if (obs.getRemoteId() != null) { @@ -57,16 +57,16 @@ public void onObservationCreated(Collection observations, Boolean s } // Should a notification be presented to the user? - if (notificationsEnabled && remoteObservations && (observations.size()) > 0) { + if (notificationsEnabled && remoteObservations && !observations.isEmpty()) { // Build intent for notification content - Intent viewIntent = new Intent(mContext, LandingActivity.class); + Intent viewIntent = new Intent(context, LandingActivity.class); //viewIntent.putExtra(EXTRA_EVENT_ID, eventId); PendingIntent viewPendingIntent = - PendingIntent.getActivity(mContext, 0, viewIntent, 0); + PendingIntent.getActivity(context, 0, viewIntent, PendingIntent.FLAG_IMMUTABLE); NotificationCompat.Builder notificationBuilder = - new NotificationCompat.Builder(mContext, MageApplication.MAGE_NOTIFICATION_CHANNEL_ID) + new NotificationCompat.Builder(context, MageApplication.MAGE_NOTIFICATION_CHANNEL_ID) .setSmallIcon(R.drawable.ic_new_obs) .setContentTitle("New MAGE Observation(s)") .setContentText("Touch for details") @@ -76,7 +76,7 @@ public void onObservationCreated(Collection observations, Boolean s .setContentIntent(viewPendingIntent); // Get an instance of the NotificationManager service - NotificationManagerCompat notificationManager = NotificationManagerCompat.from(mContext); + NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); // Build the notification and issues it with notification manager. notificationManager.notify(OBSERVATION_NOTIFICATION_ID, notificationBuilder.build());