From 1a8383bc63f298f6e0eff59a2bb696eac341c1ee Mon Sep 17 00:00:00 2001 From: Jose Olarte III Date: Fri, 28 Nov 2025 16:43:36 +0800 Subject: [PATCH] fix: update Android share intent handling for API 33+ compatibility Fix deprecation warnings and ensure future compatibility by updating getParcelableExtra() calls to use the new API introduced in Android 13 (API 33), while maintaining backward compatibility with older versions. Changes: - Update getParcelableExtra() to use typed version (Uri.class) on API 33+ - Update getParcelableArrayListExtra() to use typed version on API 33+ - Add version checks with Build.VERSION.SDK_INT >= TIRAMISU - Maintain backward compatibility for API 22-32 using deprecated API with @SuppressWarnings("deprecation") - No functional changes - share feature works identically across versions The new API (getParcelableExtra(key, Class)) was introduced in API 33 to provide type safety. The old API is deprecated but still functional on older versions, so we use runtime checks to support both. This ensures the app builds cleanly with targetSdkVersion 36 and remains compatible with minSdkVersion 22. --- .../java/app/timesafari/MainActivity.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/android/app/src/main/java/app/timesafari/MainActivity.java b/android/app/src/main/java/app/timesafari/MainActivity.java index 71a87a8d69..c40bb6923a 100644 --- a/android/app/src/main/java/app/timesafari/MainActivity.java +++ b/android/app/src/main/java/app/timesafari/MainActivity.java @@ -90,7 +90,16 @@ public class MainActivity extends BridgeActivity { // Handle single image share if (Intent.ACTION_SEND.equals(action) && type != null && type.startsWith("image/")) { - Uri imageUri = intent.getParcelableExtra(Intent.EXTRA_STREAM); + Uri imageUri; + // Use new API for API 33+ (Android 13+), fall back to deprecated API for older versions + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + imageUri = intent.getParcelableExtra(Intent.EXTRA_STREAM, Uri.class); + } else { + // Deprecated but still works on older versions + @SuppressWarnings("deprecation") + Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM); + imageUri = uri; + } if (imageUri != null) { String fileName = intent.getStringExtra(Intent.EXTRA_TEXT); processSharedImage(imageUri, fileName); @@ -98,7 +107,16 @@ public class MainActivity extends BridgeActivity { } // Handle multiple images share (we'll just process the first one) else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null && type.startsWith("image/")) { - java.util.ArrayList imageUris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM); + java.util.ArrayList imageUris; + // Use new API for API 33+ (Android 13+), fall back to deprecated API for older versions + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + imageUris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM, Uri.class); + } else { + // Deprecated but still works on older versions + @SuppressWarnings("deprecation") + java.util.ArrayList uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM); + imageUris = uris; + } if (imageUris != null && !imageUris.isEmpty()) { processSharedImage(imageUris.get(0), null); }