Skip to content

Commit ca5c8c0

Browse files
authored
feat(Leanplum): Adds getDeviceId method. (#118)
1 parent f5c0b59 commit ca5c8c0

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

AndroidSDK/src/com/leanplum/Leanplum.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,20 @@ public static void setDeviceId(String deviceId) {
295295
userSpecifiedDeviceId = true;
296296
}
297297

298+
/**
299+
* Gets the deviceId in the current Leanplum session. This should only be called after
300+
* {@link Leanplum#start}.
301+
*
302+
* @return String Returns the deviceId in the current Leanplum session.
303+
*/
304+
public static String getDeviceId() {
305+
if (!LeanplumInternal.hasCalledStart()) {
306+
Log.e("Leanplum.start() must be called before calling getDeviceId.");
307+
return null;
308+
}
309+
return Request.deviceId();
310+
}
311+
298312
/**
299313
* Sets the application context. This should be the first call to Leanplum.
300314
*/

AndroidSDKTests/src/test/java/com/leanplum/LeanplumTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,4 +1213,17 @@ public void variablesChanged() {
12131213
handlers = CollectionUtil.uncheckedCast(TestClassUtil.getField(Leanplum.class, "onceNoDownloadsHandlers"));
12141214
assertEquals(0, handlers.size());
12151215
}
1216+
1217+
/**
1218+
* Test for {@link Leanplum#getDeviceId()}.
1219+
*/
1220+
@Test
1221+
public void testGetDeviceId() {
1222+
String deviceId = Leanplum.getDeviceId();
1223+
assertNull(deviceId);
1224+
Leanplum.start(mContext);
1225+
assertTrue(Leanplum.hasStarted());
1226+
deviceId = Leanplum.getDeviceId();
1227+
assertNotNull(deviceId);
1228+
}
12161229
}

0 commit comments

Comments
 (0)