Skip to content

Commit 79e4ad8

Browse files
Fix: Boolean map customAttribute values crash on Android (#49)
1 parent 69c84b4 commit 79e4ad8

File tree

4 files changed

+34
-8
lines changed

4 files changed

+34
-8
lines changed

android/src/main/java/com/mparticle/react/MParticleModule.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,34 @@ private static Map<String, String> ConvertStringMap(ReadableMap readableMap) {
716716
ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
717717
while (iterator.hasNextKey()) {
718718
String key = iterator.nextKey();
719-
map.put(key, readableMap.getString(key));
719+
switch (readableMap.getType(key)) {
720+
case Null:
721+
map.put(key, null);
722+
break;
723+
case Boolean:
724+
map.put(key, Boolean.valueOf(readableMap.getBoolean(key)).toString());
725+
break;
726+
case Number:
727+
try {
728+
map.put(key, Integer.toString(readableMap.getInt(key)));
729+
} catch (Exception e) {
730+
try {
731+
map.put(key, Double.toString(readableMap.getDouble(key)));
732+
} catch (Exception ex) {
733+
Logger.warning("Unable to parse value for \"" + key + "\"");
734+
}
735+
}
736+
break;
737+
case String:
738+
map.put(key, readableMap.getString(key));
739+
break;
740+
case Map:
741+
Logger.warning("Maps are not supported Attribute value types");
742+
break;
743+
case Array:
744+
Logger.warning("Lists are not supported Attribute value types");
745+
break;
746+
}
720747
}
721748
}
722749

sample/android/app/build.gradle

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,9 @@ android {
126126
}
127127

128128
dependencies {
129-
compile project(':react-native-mparticle')
130-
compile fileTree(dir: "libs", include: ["*.jar"])
131-
compile "com.android.support:appcompat-v7:28+"
132-
compile "com.facebook.react:react-native:+" // From node_modules
129+
implementation project(':react-native-mparticle')
130+
implementation fileTree(dir: "libs", include: ["*.jar"])
131+
implementation "com.facebook.react:react-native:+" // From node_modules
133132

134133
//
135134
// In your app, you should include mParticle core like this:
@@ -138,7 +137,7 @@ dependencies {
138137
//
139138
// (See https://github.com/mparticle/mparticle-android-sdk for the latest version)
140139
//
141-
compile "com.mparticle:android-core:5.+"
140+
implementation "com.mparticle:android-core:5.+"
142141

143142
//
144143
// And, if you want to include kits, you can do so as follows:

sample/android/app/src/main/java/com/mparticlesample/MainApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void onCreate() {
4848
IdentityApiRequest.Builder identityRequest = IdentityApiRequest.withEmptyUser();
4949

5050
MParticleOptions options = MParticleOptions.builder(this)
51-
.credentials("REPLACE ME WITH KEY","REPLACE ME WITH SECRET")
51+
.credentials("us1-352af4d005e49047a7bcc78281f33e9c","flR34mIajnAA5F-Ouha7JQF5v0JqFUfo_QjJtM_16VESU2hS0ikp3hRILG70-aBk")
5252
.logLevel(MParticle.LogLevel.VERBOSE)
5353
.identify(identityRequest.build())
5454
.build();

sample/index.android.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export default class MParticleSample extends Component {
8686
var i = 0;
8787
// Toggle the state every few seconds, 10 times
8888
var intervalId = setInterval(() => {
89-
MParticle.logEvent('Test event', MParticle.EventType.Other, { 'Test key': 'Test value' })
89+
MParticle.logEvent('Test event', MParticle.EventType.Other, { 'Test key': 'Test value', 'Test Boolean': true, 'Test Int': 1235, 'Test Double': 123.123 })
9090
this.setState((previousState) => {
9191
return {isShowingText: !previousState.isShowingText}
9292
})

0 commit comments

Comments
 (0)