com.samsung.android.sdk.healthdata
Class HealthDataUtil
- java.lang.Object
-
- com.samsung.android.sdk.healthdata.HealthDataUtil
-
public class HealthDataUtil extends Object
This class provides useful utilities.HealthDataUtil
makes compressed JSON conversion easy.
SupposeLiveData
class that defines as theHealthConstants.Exercise.LIVE_DATA
's JSON format.public class LiveData { long start_time = 0L; float heart_rate = 0.f; float cadence = 0.f; float count = 0.f; float power = 0.f; float speed = 0.f; }
Make sure to add GSON as a Maven dependency to your project:
dependencies { ... implementation "com.google.code.gson:gson:2.7" }
Converting data to compressed JSON
LIVE_DATA
can be retrieved as the example below.public byte[] createLiveData(List<LiveData> liveDataList) { // convert data class to JSON string byte[] zip = HealthDataUtil.getJsonBlob(liveDataList); return zip; }
Getting data from compressed JSON
You can read detailed information of exercise data after decompressing them.public List<LiveData> getLiveData(byte[] zip) { // decompress ZIP List<LiveData> liveDataList = HealthDataUtil.getStructuredDataList(zip, LiveData.class); return liveDataList; }
- Since:
- 1.3.0
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static <T> byte[]
getJsonBlob(List<T> structuredDataList)
Converts a given input List object to the raw data which is formatted with JSON and compressed.static <T> byte[]
getJsonBlob(T structuredData)
Converts a given input object to the raw data which is formatted with JSON and compressed.static <T> T
getStructuredData(byte[] jsonBlob, Class<T> clazz)
Converts a given raw data to the particular class type.static <T> List<T>
getStructuredDataList(byte[] jsonBlob, Class<T> clazz)
Converts a given raw data to the List of particular class type.
-
-
-
Method Detail
-
getJsonBlob
public static <T> byte[] getJsonBlob(T structuredData)
Converts a given input object to the raw data which is formatted with JSON and compressed.- Parameters:
structuredData
- An object of a specified class- Returns:
- Compressed BLOB data with the JSON format
- Throws:
IllegalStateException
- If an untreatable error has occurred
-
getJsonBlob
public static <T> byte[] getJsonBlob(List<T> structuredDataList)
Converts a given input List object to the raw data which is formatted with JSON and compressed.- Parameters:
structuredDataList
- An object for which JSON blob is to be created- Returns:
- Compressed BLOB data with the JSON format
- Throws:
IllegalStateException
- If an untreatable error has occurred
-
getStructuredData
public static <T> T getStructuredData(byte[] jsonBlob, Class<T> clazz)
Converts a given raw data to the particular class type.- Parameters:
jsonBlob
- Compressed BLOB data which is formatted with JSON and compressedclazz
- A class object of the destination instance- Returns:
- A converted
T
type object from the compressed BLOB data - Throws:
IllegalArgumentException
- If JSON is invalid representation for an object typeIllegalStateException
- If an untreatable error has occurred
-
getStructuredDataList
public static <T> List<T> getStructuredDataList(byte[] jsonBlob, Class<T> clazz)
Converts a given raw data to the List of particular class type.- Parameters:
jsonBlob
- Compressed BLOB data which is formatted with JSON and compressedclazz
- A class object of the destination instance- Returns:
- An converted
T
type object from the compressed BLOB data - Throws:
IllegalArgumentException
- If JSON is invalid representation for an object typeIllegalStateException
- If an untreatable error has occurred
-
-