public class HealthUserProfile extends Object
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.
0.0
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."); } } }; }
static int
GENDER_FEMALE
GENDER_MALE
GENDER_UNKNOWN
String
getBirthDate()
int
getGender()
float
getHeight()
Bitmap
getImage()
static HealthUserProfile
getProfile(HealthDataStore store)
HealthUserProfile
getUserId()
getUserName()
getWeight()
public static final int GENDER_UNKNOWN
0
public static final int GENDER_MALE
1
public static final int GENDER_FEMALE
2
public static HealthUserProfile getProfile(HealthDataStore store)
HealthConstants.USER_PROFILE_DATA_TYPE
store
IllegalArgumentException
IllegalStateException
SecurityException
public String getBirthDate()
yyyymmdd
public float getHeight()
public float getWeight()
@Deprecated public String getUserId()
public int getGender()
public String getUserName()
@Deprecated public Bitmap getImage()
null