com.samsung.android.sdk.healthdata
Class HealthUserProfile
- java.lang.Object
-
- com.samsung.android.sdk.healthdata.HealthUserProfile
-
public class HealthUserProfile extends Object
This class provides a user profile. It handles the user's following information:- Date of birth
- Gender
- Height
- Weight
- Nickname
Getting User Profile
Samsung Health's user profile is read-only and you can get it after acquiring the user's permission.Set the user profile data type's permission info in the manifest.
<manifest . . . > <application . . . > <meta-data android:name="com.samsung.android.health.permission.read" android:value="com.samsung.health.user_profile"/> </application . . . > </manifest . . . >
Getting the user profile is same with other data type access.
Returning an empty string,0.0
, or unknown value can be retrieved for each property means that the user doesn't fill out Samsung Health's profile.public class MainActivity extends Activity { // The state of connection private HealthDataStore mStore; // Permission key set Set<HealthPermissionManager.PermissionKey> mKeySet = new HashSet<HealthPermissionManager.PermissionKey>(); public static final String APP_TAG = "MyApp"; private void getUserProfile() { // Adds a permission to read a user profile to the permission key set mKeySet.add(new HealthPermissionManager.PermissionKey(HealthConstants.USER_PROFILE_DATA_TYPE, HealthPermissionManager.PermissionType.READ)); HealthPermissionManager pmsManager = new HealthPermissionManager(mStore); try { // Checks if a user profile permission is acquired Map<HealthPermissionManager.PermissionKey, Boolean> keyMap = pmsManager.isPermissionAcquired(mKeySet); // Request permission if the user profile permission is not acquired if(keyMap.containsValue(Boolean.FALSE)) { pmsManager.requestPermissions(mKeySet, MainActivity.this).setResultListener(mPermissionListener); } } catch(Exception e) { Log.d(APP_TAG, "requestPermissions() fails."); } } private final HealthResultHolder.ResultListener<HealthPermissionManager.PermissionResult> mPermissionListener = new HealthResultHolder.ResultListener<HealthPermissionManager.PermissionResult>() { @Override public void onResult(HealthPermissionManager.PermissionResult permissionResult) { Map<HealthPermissionManager.PermissionKey, Boolean> resultMap = permissionResult.getResultMap(); if (resultMap.containsValue(Boolean.TRUE)) { // Gets the user profile if permission is acquired try { HealthUserProfile usrProfile = HealthUserProfile.getProfile(mStore); // Date of birth - yyyymmdd String birthDate = usrProfile.getBirthDate(); if (birthDate.isEmpty()) { Log.d(APP_TAG, "Date of birth is not set by the user yet."); } // Gender int gender = usrProfile.getGender(); if (gender == HealthUserProfile.GENDER_UNKNOWN) { Log.d(APP_TAG, "Gender is not set by the user yet."); } // Height float height = usrProfile.getHeight(); if (height == 0.0f) { Log.d(APP_TAG, "Height is not set by the user yet."); } // Weight float weight = usrProfile.getWeight(); if (weight == 0.0f) { Log.d(APP_TAG, "Weight is not set by the user yet."); } } else { Log.d(TAG, "Fail to get permission."); } } }; }
- Since:
- 1.0.0
-
-
Field Summary
Fields Modifier and Type Field and Description static int
GENDER_FEMALE
Female as the value of gender.static int
GENDER_MALE
Male as the value of gender.static int
GENDER_UNKNOWN
Unknown as the value of gender.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method and Description String
getBirthDate()
Gets the user's date of birth.int
getGender()
Gets the gender of the user.float
getHeight()
Gets the latest height of the user.Bitmap
getImage()
Deprecated.It will removed. Do not use any more.static HealthUserProfile
getProfile(HealthDataStore store)
Gets aHealthUserProfile
instance.String
getUserId()
Deprecated.It will removed. Do not use any more.String
getUserName()
Gets the nickname that the user entered in Samsung Health.float
getWeight()
Gets the latest weight of the the user.
-
-
-
Field Detail
-
GENDER_UNKNOWN
public static final int GENDER_UNKNOWN
Unknown as the value of gender. Its constant value is0
.- See Also:
- Constant Field Values
-
GENDER_MALE
public static final int GENDER_MALE
Male as the value of gender. Its constant value is1
.- See Also:
- Constant Field Values
-
GENDER_FEMALE
public static final int GENDER_FEMALE
Female as the value of gender. Its constant value is2
.- See Also:
- Constant Field Values
-
-
Method Detail
-
getProfile
public static HealthUserProfile getProfile(HealthDataStore store)
Gets aHealthUserProfile
instance. It works after acquiring permission forHealthConstants.USER_PROFILE_DATA_TYPE
.- Parameters:
store
- The connection to the health data store- Returns:
- The
HealthUserProfile
instance - Throws:
IllegalArgumentException
- If the specified input is invalidIllegalStateException
- If the connection to the health data store is invalid or
a remote-invocation error occurs on the connectionSecurityException
- If permission forHealthConstants.USER_PROFILE_DATA_TYPE
is not acquired- Since:
- 1.0.0
-
getBirthDate
public String getBirthDate()
Gets the user's date of birth.- Returns:
- The user's date of birth with the
yyyymmdd
format.
If it returns the empty string, it means the user doesn't set the birth date on the profile page of Samsung Health. - Since:
- 1.0.0
-
getHeight
public float getHeight()
Gets the latest height of the user. The unit is centimeter.- Returns:
- The height of the user.
If it returns0.0
, it means the user doesn't set the height on the profile page of Samsung Health. - Since:
- 1.0.0
-
getWeight
public float getWeight()
Gets the latest weight of the the user. The unit is kilogram.- Returns:
- The weight of the user.
If it returns0.0
, it means the user doesn't set the weight on the profile page of Samsung Health. - Since:
- 1.0.0
-
getUserId
@Deprecated public String getUserId()
Deprecated. It will removed. Do not use any more.Gets an empty string.- Returns:
- empty string
- Since:
- 1.0.0
-
getGender
public int getGender()
Gets the gender of the user.- Returns:
- The gender of the user. One of the following values is returned.
GENDER_UNKNOWN
, if the user doesn't set the gender info on the profile page of Samsung HealthGENDER_MALE
GENDER_FEMALE
- Since:
- 1.0.0
-
getUserName
public String getUserName()
Gets the nickname that the user entered in Samsung Health.- Returns:
- The user's nickname.
It returns the empty string. - Since:
- 1.2.0
-
getImage
@Deprecated public Bitmap getImage()
Deprecated. It will removed. Do not use any more.Gets null.- Returns:
null
.- Since:
- 1.2.0
-
-