From 99a4cf32d65e7074824c3182f853f8b72fd4f7db Mon Sep 17 00:00:00 2001 From: Rui Mendes Date: Thu, 18 Jun 2026 15:09:11 +0100 Subject: [PATCH 1/3] refactor(android): replace deprecated Bundle.get(String) --- .../LocalNotificationsPlugin.java | 43 +++++++++++++++++- .../PushNotificationsPlugin.java | 44 ++++++++++++++++++- 2 files changed, 84 insertions(+), 3 deletions(-) diff --git a/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationsPlugin.java b/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationsPlugin.java index 197de4ae6..ebcf36f70 100644 --- a/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationsPlugin.java +++ b/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationsPlugin.java @@ -10,8 +10,11 @@ import android.content.Intent; import android.net.Uri; import android.os.Build; +import android.os.Bundle; +import android.os.Parcelable; import android.service.notification.StatusBarNotification; import androidx.activity.result.ActivityResult; +import androidx.core.os.BundleCompat; import com.getcapacitor.Bridge; import com.getcapacitor.JSArray; import com.getcapacitor.JSObject; @@ -24,6 +27,8 @@ import com.getcapacitor.annotation.CapacitorPlugin; import com.getcapacitor.annotation.Permission; import com.getcapacitor.annotation.PermissionCallback; +import java.io.Serializable; +import java.util.Arrays; import java.util.List; import java.util.Map; import org.json.JSONArray; @@ -141,7 +146,7 @@ public void getDeliveredNotifications(PluginCall call) { JSObject extras = new JSObject(); for (String key : notification.extras.keySet()) { - extras.put(key, notification.extras.get(key)); + extras.put(key, extractBundleValue(notification.extras, key)); } jsNotif.put("data", extras); @@ -287,6 +292,42 @@ public static void fireReceived(JSObject notification) { } } + private static Object extractBundleValue(Bundle bundle, String key) { + if (!bundle.containsKey(key)) return null; + + String s = bundle.getString(key); + if (s != null) return s; + + CharSequence cs = bundle.getCharSequence(key); + if (cs != null) return cs.toString(); + + String[] sArr = bundle.getStringArray(key); + if (sArr != null) return new JSONArray(Arrays.asList(sArr)); + + int iMin = bundle.getInt(key, Integer.MIN_VALUE); + if (iMin == bundle.getInt(key, Integer.MAX_VALUE)) return iMin; + + long lMin = bundle.getLong(key, Long.MIN_VALUE); + if (lMin == bundle.getLong(key, Long.MAX_VALUE)) return lMin; + + double dNeg = bundle.getDouble(key, -1d); + if (Double.compare(dNeg, bundle.getDouble(key, 1d)) == 0) return dNeg; + + float fNeg = bundle.getFloat(key, -1f); + if (Float.compare(fNeg, bundle.getFloat(key, 1f)) == 0) return fNeg; + + boolean bTrue = bundle.getBoolean(key, true); + if (bTrue == bundle.getBoolean(key, false)) return bTrue; + + Parcelable parcelable = BundleCompat.getParcelable(bundle, key, Parcelable.class); + if (parcelable != null) return parcelable.toString(); + + Serializable serializable = BundleCompat.getSerializable(bundle, key, Serializable.class); + if (serializable != null) return serializable.toString(); + + return null; + } + public static LocalNotificationsPlugin getLocalNotificationsInstance() { if (staticBridge != null && staticBridge.getWebView() != null) { PluginHandle handle = staticBridge.getPlugin("LocalNotifications"); diff --git a/push-notifications/android/src/main/java/com/capacitorjs/plugins/pushnotifications/PushNotificationsPlugin.java b/push-notifications/android/src/main/java/com/capacitorjs/plugins/pushnotifications/PushNotificationsPlugin.java index 140df28e0..6b79ff957 100644 --- a/push-notifications/android/src/main/java/com/capacitorjs/plugins/pushnotifications/PushNotificationsPlugin.java +++ b/push-notifications/android/src/main/java/com/capacitorjs/plugins/pushnotifications/PushNotificationsPlugin.java @@ -10,7 +10,9 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; +import android.os.Parcelable; import android.service.notification.StatusBarNotification; +import androidx.core.os.BundleCompat; import com.getcapacitor.*; import com.getcapacitor.annotation.CapacitorPlugin; import com.getcapacitor.annotation.Permission; @@ -19,8 +21,10 @@ import com.google.firebase.messaging.FirebaseMessaging; import com.google.firebase.messaging.NotificationParams; import com.google.firebase.messaging.RemoteMessage; +import java.io.Serializable; import java.util.Arrays; import java.util.List; +import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -65,7 +69,7 @@ protected void handleOnNewIntent(Intent data) { if (key.equals("google.message_id")) { notificationJson.put("id", bundle.getString(key)); } else { - dataObject.put(key, bundle.get(key)); + dataObject.put(key, extractBundleValue(bundle, key)); } } notificationJson.put("data", dataObject); @@ -141,7 +145,7 @@ public void getDeliveredNotifications(PluginCall call) { JSObject extras = new JSObject(); for (String key : notification.extras.keySet()) { - extras.put(key, notification.extras.get(key)); + extras.put(key, extractBundleValue(notification.extras, key)); } jsNotif.put("data", extras); @@ -312,6 +316,42 @@ private void permissionsCallback(PluginCall call) { this.checkPermissions(call); } + private static Object extractBundleValue(Bundle bundle, String key) { + if (!bundle.containsKey(key)) return null; + + String s = bundle.getString(key); + if (s != null) return s; + + CharSequence cs = bundle.getCharSequence(key); + if (cs != null) return cs.toString(); + + String[] sArr = bundle.getStringArray(key); + if (sArr != null) return new JSONArray(Arrays.asList(sArr)); + + int iMin = bundle.getInt(key, Integer.MIN_VALUE); + if (iMin == bundle.getInt(key, Integer.MAX_VALUE)) return iMin; + + long lMin = bundle.getLong(key, Long.MIN_VALUE); + if (lMin == bundle.getLong(key, Long.MAX_VALUE)) return lMin; + + double dNeg = bundle.getDouble(key, -1d); + if (Double.compare(dNeg, bundle.getDouble(key, 1d)) == 0) return dNeg; + + float fNeg = bundle.getFloat(key, -1f); + if (Float.compare(fNeg, bundle.getFloat(key, 1f)) == 0) return fNeg; + + boolean bTrue = bundle.getBoolean(key, true); + if (bTrue == bundle.getBoolean(key, false)) return bTrue; + + Parcelable parcelable = BundleCompat.getParcelable(bundle, key, Parcelable.class); + if (parcelable != null) return parcelable.toString(); + + Serializable serializable = BundleCompat.getSerializable(bundle, key, Serializable.class); + if (serializable != null) return serializable.toString(); + + return null; + } + @SuppressWarnings("deprecation") private Bundle getBundleLegacy() { try { From 527a928a0a3fdb5117d3ef8af634e66a67527476 Mon Sep 17 00:00:00 2001 From: Rui Mendes Date: Fri, 19 Jun 2026 15:00:23 +0100 Subject: [PATCH 2/3] drop unneeded static on extractBundleValue --- .../plugins/localnotifications/LocalNotificationsPlugin.java | 2 +- .../plugins/pushnotifications/PushNotificationsPlugin.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationsPlugin.java b/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationsPlugin.java index ebcf36f70..8c09e0799 100644 --- a/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationsPlugin.java +++ b/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationsPlugin.java @@ -292,7 +292,7 @@ public static void fireReceived(JSObject notification) { } } - private static Object extractBundleValue(Bundle bundle, String key) { + private Object extractBundleValue(Bundle bundle, String key) { if (!bundle.containsKey(key)) return null; String s = bundle.getString(key); diff --git a/push-notifications/android/src/main/java/com/capacitorjs/plugins/pushnotifications/PushNotificationsPlugin.java b/push-notifications/android/src/main/java/com/capacitorjs/plugins/pushnotifications/PushNotificationsPlugin.java index 6b79ff957..3271fa16d 100644 --- a/push-notifications/android/src/main/java/com/capacitorjs/plugins/pushnotifications/PushNotificationsPlugin.java +++ b/push-notifications/android/src/main/java/com/capacitorjs/plugins/pushnotifications/PushNotificationsPlugin.java @@ -316,7 +316,7 @@ private void permissionsCallback(PluginCall call) { this.checkPermissions(call); } - private static Object extractBundleValue(Bundle bundle, String key) { + private Object extractBundleValue(Bundle bundle, String key) { if (!bundle.containsKey(key)) return null; String s = bundle.getString(key); From 3e119d41dec101f907e019a58f2d2d507f081e7d Mon Sep 17 00:00:00 2001 From: Rui Mendes Date: Fri, 19 Jun 2026 16:47:35 +0100 Subject: [PATCH 3/3] suppress Bundle.get(String) deprecation warning --- .../LocalNotificationsPlugin.java | 44 +----------------- .../PushNotificationsPlugin.java | 46 ++----------------- 2 files changed, 6 insertions(+), 84 deletions(-) diff --git a/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationsPlugin.java b/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationsPlugin.java index 8c09e0799..f7697b4bb 100644 --- a/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationsPlugin.java +++ b/local-notifications/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationsPlugin.java @@ -10,11 +10,8 @@ import android.content.Intent; import android.net.Uri; import android.os.Build; -import android.os.Bundle; -import android.os.Parcelable; import android.service.notification.StatusBarNotification; import androidx.activity.result.ActivityResult; -import androidx.core.os.BundleCompat; import com.getcapacitor.Bridge; import com.getcapacitor.JSArray; import com.getcapacitor.JSObject; @@ -27,8 +24,6 @@ import com.getcapacitor.annotation.CapacitorPlugin; import com.getcapacitor.annotation.Permission; import com.getcapacitor.annotation.PermissionCallback; -import java.io.Serializable; -import java.util.Arrays; import java.util.List; import java.util.Map; import org.json.JSONArray; @@ -126,6 +121,7 @@ public void areEnabled(PluginCall call) { } @PluginMethod + @SuppressWarnings("deprecation") public void getDeliveredNotifications(PluginCall call) { JSArray notifications = new JSArray(); StatusBarNotification[] activeNotifications = notificationManager.getActiveNotifications(); @@ -146,7 +142,7 @@ public void getDeliveredNotifications(PluginCall call) { JSObject extras = new JSObject(); for (String key : notification.extras.keySet()) { - extras.put(key, extractBundleValue(notification.extras, key)); + extras.put(key, notification.extras.get(key)); } jsNotif.put("data", extras); @@ -292,42 +288,6 @@ public static void fireReceived(JSObject notification) { } } - private Object extractBundleValue(Bundle bundle, String key) { - if (!bundle.containsKey(key)) return null; - - String s = bundle.getString(key); - if (s != null) return s; - - CharSequence cs = bundle.getCharSequence(key); - if (cs != null) return cs.toString(); - - String[] sArr = bundle.getStringArray(key); - if (sArr != null) return new JSONArray(Arrays.asList(sArr)); - - int iMin = bundle.getInt(key, Integer.MIN_VALUE); - if (iMin == bundle.getInt(key, Integer.MAX_VALUE)) return iMin; - - long lMin = bundle.getLong(key, Long.MIN_VALUE); - if (lMin == bundle.getLong(key, Long.MAX_VALUE)) return lMin; - - double dNeg = bundle.getDouble(key, -1d); - if (Double.compare(dNeg, bundle.getDouble(key, 1d)) == 0) return dNeg; - - float fNeg = bundle.getFloat(key, -1f); - if (Float.compare(fNeg, bundle.getFloat(key, 1f)) == 0) return fNeg; - - boolean bTrue = bundle.getBoolean(key, true); - if (bTrue == bundle.getBoolean(key, false)) return bTrue; - - Parcelable parcelable = BundleCompat.getParcelable(bundle, key, Parcelable.class); - if (parcelable != null) return parcelable.toString(); - - Serializable serializable = BundleCompat.getSerializable(bundle, key, Serializable.class); - if (serializable != null) return serializable.toString(); - - return null; - } - public static LocalNotificationsPlugin getLocalNotificationsInstance() { if (staticBridge != null && staticBridge.getWebView() != null) { PluginHandle handle = staticBridge.getPlugin("LocalNotifications"); diff --git a/push-notifications/android/src/main/java/com/capacitorjs/plugins/pushnotifications/PushNotificationsPlugin.java b/push-notifications/android/src/main/java/com/capacitorjs/plugins/pushnotifications/PushNotificationsPlugin.java index 3271fa16d..8622e6f07 100644 --- a/push-notifications/android/src/main/java/com/capacitorjs/plugins/pushnotifications/PushNotificationsPlugin.java +++ b/push-notifications/android/src/main/java/com/capacitorjs/plugins/pushnotifications/PushNotificationsPlugin.java @@ -10,9 +10,7 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; -import android.os.Parcelable; import android.service.notification.StatusBarNotification; -import androidx.core.os.BundleCompat; import com.getcapacitor.*; import com.getcapacitor.annotation.CapacitorPlugin; import com.getcapacitor.annotation.Permission; @@ -21,10 +19,8 @@ import com.google.firebase.messaging.FirebaseMessaging; import com.google.firebase.messaging.NotificationParams; import com.google.firebase.messaging.RemoteMessage; -import java.io.Serializable; import java.util.Arrays; import java.util.List; -import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -59,6 +55,7 @@ public void load() { } @Override + @SuppressWarnings("deprecation") protected void handleOnNewIntent(Intent data) { super.handleOnNewIntent(data); Bundle bundle = data.getExtras(); @@ -69,7 +66,7 @@ protected void handleOnNewIntent(Intent data) { if (key.equals("google.message_id")) { notificationJson.put("id", bundle.getString(key)); } else { - dataObject.put(key, extractBundleValue(bundle, key)); + dataObject.put(key, bundle.get(key)); } } notificationJson.put("data", dataObject); @@ -125,6 +122,7 @@ public void unregister(PluginCall call) { } @PluginMethod + @SuppressWarnings("deprecation") public void getDeliveredNotifications(PluginCall call) { JSArray notifications = new JSArray(); StatusBarNotification[] activeNotifications = notificationManager.getActiveNotifications(); @@ -145,7 +143,7 @@ public void getDeliveredNotifications(PluginCall call) { JSObject extras = new JSObject(); for (String key : notification.extras.keySet()) { - extras.put(key, extractBundleValue(notification.extras, key)); + extras.put(key, notification.extras.get(key)); } jsNotif.put("data", extras); @@ -316,42 +314,6 @@ private void permissionsCallback(PluginCall call) { this.checkPermissions(call); } - private Object extractBundleValue(Bundle bundle, String key) { - if (!bundle.containsKey(key)) return null; - - String s = bundle.getString(key); - if (s != null) return s; - - CharSequence cs = bundle.getCharSequence(key); - if (cs != null) return cs.toString(); - - String[] sArr = bundle.getStringArray(key); - if (sArr != null) return new JSONArray(Arrays.asList(sArr)); - - int iMin = bundle.getInt(key, Integer.MIN_VALUE); - if (iMin == bundle.getInt(key, Integer.MAX_VALUE)) return iMin; - - long lMin = bundle.getLong(key, Long.MIN_VALUE); - if (lMin == bundle.getLong(key, Long.MAX_VALUE)) return lMin; - - double dNeg = bundle.getDouble(key, -1d); - if (Double.compare(dNeg, bundle.getDouble(key, 1d)) == 0) return dNeg; - - float fNeg = bundle.getFloat(key, -1f); - if (Float.compare(fNeg, bundle.getFloat(key, 1f)) == 0) return fNeg; - - boolean bTrue = bundle.getBoolean(key, true); - if (bTrue == bundle.getBoolean(key, false)) return bTrue; - - Parcelable parcelable = BundleCompat.getParcelable(bundle, key, Parcelable.class); - if (parcelable != null) return parcelable.toString(); - - Serializable serializable = BundleCompat.getSerializable(bundle, key, Serializable.class); - if (serializable != null) return serializable.toString(); - - return null; - } - @SuppressWarnings("deprecation") private Bundle getBundleLegacy() { try {