public static MobileDevice convertToMobileDevice(Device device) { MobileDevice mobileDevice = null; if (device != null) { mobileDevice = new MobileDevice(); mobileDevice.setMobileDeviceId(device.getDeviceIdentifier()); mobileDevice.setImei(getPropertyValue(device, MOBILE_DEVICE_IMEI)); mobileDevice.setImsi(getPropertyValue(device, MOBILE_DEVICE_IMSI)); mobileDevice.setModel(getPropertyValue(device, MOBILE_DEVICE_MODEL)); mobileDevice.setOsVersion(getPropertyValue(device, MOBILE_DEVICE_OS_VERSION)); mobileDevice.setVendor(getPropertyValue(device, MOBILE_DEVICE_VENDOR)); mobileDevice.setLatitude(getPropertyValue(device, MOBILE_DEVICE_LATITUDE)); mobileDevice.setLongitude(getPropertyValue(device, MOBILE_DEVICE_LONGITUDE)); mobileDevice.setSerial(getPropertyValue(device, MOBILE_DEVICE_SERIAL)); mobileDevice.setOsBuildDate(getPropertyValue(device, MOBILE_DEVICE_OS_BUILD_DATE)); if (device.getProperties() != null) { Map<String, String> deviceProperties = new HashMap<String, String>(); for (Device.Property deviceProperty : device.getProperties()) { deviceProperties.put(deviceProperty.getName(), deviceProperty.getValue()); } mobileDevice.setDeviceProperties(deviceProperties); } else { mobileDevice.setDeviceProperties(new HashMap<String, String>()); } } return mobileDevice; }
private static Device.Property getProperty(String property, String value) { if (property != null) { Device.Property prop = new Device.Property(); prop.setName(property); prop.setValue(value); return prop; } return null; }
private static String getPropertyValue(Device device, String property) { if (device != null && device.getProperties() != null) { for (Device.Property prop : device.getProperties()) { if (property.equals(prop.getName())) { return prop.getValue(); } } } return null; }
public static String getDeviceProperty( List<Device.Property> deviceProperties, String propertyKey) { String deviceProperty = ""; for (Device.Property property : deviceProperties) { if (propertyKey.equals(property.getName())) { deviceProperty = property.getValue(); } } return deviceProperty; }