From 86f8d0bb528a75777c357ae214643ed58c326ca9 Mon Sep 17 00:00:00 2001 From: Vladyslav Stepanov Date: Tue, 12 Apr 2022 16:35:40 -0700 Subject: [PATCH] Fix Android implementation for Linking.sendIntent() Summary: Changelog: [Android][Fixed] - Fix Extras usage in Android implementation of Linking.sendIntent() The implementation of sendIntent() has a bug in a way it uses extras map. From JS layer the API sends and array of map, where each map contains exactly 2 entries: {"key" -> "name_of_extra_to_use", "value" -> value_of_extra_to_use} However Java parsing was just picking a random pair out of this map and was sending it as extra. Most frequently the result was "value" -> value_of_extra_to_use in Intent instead of name_of_extra_to_use -> value_of_extra_to_use This diff fixes the problem Reviewed By: lunaleaps Differential Revision: D35516496 fbshipit-source-id: 7da0a1cb3b8aa30463004dbb47008c83d8e95bd1 --- .../facebook/react/modules/intent/IntentModule.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/intent/IntentModule.java b/ReactAndroid/src/main/java/com/facebook/react/modules/intent/IntentModule.java index e0f5b87847f..7b532d4975b 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/intent/IntentModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/intent/IntentModule.java @@ -30,6 +30,8 @@ public class IntentModule extends NativeIntentAndroidSpec { public static final String NAME = "IntentAndroid"; + private static final String EXTRA_MAP_KEY_FOR_VALUE = "value"; + public IntentModule(ReactApplicationContext reactContext) { super(reactContext); } @@ -184,13 +186,13 @@ public class IntentModule extends NativeIntentAndroidSpec { if (extras != null) { for (int i = 0; i < extras.size(); i++) { ReadableMap map = extras.getMap(i); - String name = map.keySetIterator().nextKey(); - ReadableType type = map.getType(name); + String name = map.getString("key"); + ReadableType type = map.getType(EXTRA_MAP_KEY_FOR_VALUE); switch (type) { case String: { - intent.putExtra(name, map.getString(name)); + intent.putExtra(name, map.getString(EXTRA_MAP_KEY_FOR_VALUE)); break; } case Number: @@ -198,13 +200,13 @@ public class IntentModule extends NativeIntentAndroidSpec { // We cannot know from JS if is an Integer or Double // See: https://github.com/facebook/react-native/issues/4141 // We might need to find a workaround if this is really an issue - Double number = map.getDouble(name); + Double number = map.getDouble(EXTRA_MAP_KEY_FOR_VALUE); intent.putExtra(name, number); break; } case Boolean: { - intent.putExtra(name, map.getBoolean(name)); + intent.putExtra(name, map.getBoolean(EXTRA_MAP_KEY_FOR_VALUE)); break; } default: