Skip to content

Commit 86f8d0b

Browse files
Vladyslav Stepanovfacebook-github-bot
Vladyslav Stepanov
authored andcommitted
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
1 parent 46ab59c commit 86f8d0b

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

ReactAndroid/src/main/java/com/facebook/react/modules/intent/IntentModule.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public class IntentModule extends NativeIntentAndroidSpec {
3030

3131
public static final String NAME = "IntentAndroid";
3232

33+
private static final String EXTRA_MAP_KEY_FOR_VALUE = "value";
34+
3335
public IntentModule(ReactApplicationContext reactContext) {
3436
super(reactContext);
3537
}
@@ -184,27 +186,27 @@ public void sendIntent(String action, @Nullable ReadableArray extras, Promise pr
184186
if (extras != null) {
185187
for (int i = 0; i < extras.size(); i++) {
186188
ReadableMap map = extras.getMap(i);
187-
String name = map.keySetIterator().nextKey();
188-
ReadableType type = map.getType(name);
189+
String name = map.getString("key");
190+
ReadableType type = map.getType(EXTRA_MAP_KEY_FOR_VALUE);
189191

190192
switch (type) {
191193
case String:
192194
{
193-
intent.putExtra(name, map.getString(name));
195+
intent.putExtra(name, map.getString(EXTRA_MAP_KEY_FOR_VALUE));
194196
break;
195197
}
196198
case Number:
197199
{
198200
// We cannot know from JS if is an Integer or Double
199201
// See: https://github.com/facebook/react-native/issues/4141
200202
// We might need to find a workaround if this is really an issue
201-
Double number = map.getDouble(name);
203+
Double number = map.getDouble(EXTRA_MAP_KEY_FOR_VALUE);
202204
intent.putExtra(name, number);
203205
break;
204206
}
205207
case Boolean:
206208
{
207-
intent.putExtra(name, map.getBoolean(name));
209+
intent.putExtra(name, map.getBoolean(EXTRA_MAP_KEY_FOR_VALUE));
208210
break;
209211
}
210212
default:

0 commit comments

Comments
 (0)