9. 健康设置

管理设备的设置功能,具体设置项有:传感器设置、久坐提醒、连续测量心率、运动心率提醒、睡眠检测、跌倒检测、抬腕检测、个人信息、蓝牙断开提醒

9.1. 读取设置状态

//WatchManager是WatchOpImpl的子类,须在1.3配置好sdk
WatchManager watchManager = WatchManager.getInstance();
//初始化健康功能实现
HealthOpImpl healthOp = new HealthOpImpl(watchManager);
//注册RCSP事件监听器
healthOp.getRcspOp().registerOnRcspEventListener(new OnRcspEventListener() {
    @Override
    public void onHealthSettingChange(BluetoothDevice device, HealthSettingInfo healthSettingInfo) {
        //此处将会回调健康设置信息
        int funcFlag = healthSettingInfo.getFuncFlag(); //当前功能码标志
        switch (funcFlag){
            case AttrAndFunCode.HEALTH_SETTING_TYPE_SENSOR://传感器设置开关
                SensorInfo sensorInfo = healthSettingInfo.getSensorInfo();
                break;
            case AttrAndFunCode.HEALTH_SETTING_TYPE_SEDENTARY_REMINDER://久坐提醒
                SedentaryReminder sedentaryReminder = healthSettingInfo.getSedentaryReminder();
                break;
            case AttrAndFunCode.HEALTH_SETTING_TYPE_HEART_RATE_MEASURE://心率连续测量
                HeartRateMeasure heartRateMeasure = healthSettingInfo.getHeartRateMeasure();
                break;
            case AttrAndFunCode.HEALTH_SETTING_TYPE_EXERCISE_HEART_RATE_REMINDER: //运动心率测量
                ExerciseHeartRateReminder exerciseHeartRateReminder = healthSettingInfo.getExerciseHeartRateReminder();
                break;
            case AttrAndFunCode.HEALTH_SETTING_TYPE_AUTOMATIC_PRESSURE_DETECTION://压力自动检测
                AutomaticPressureDetection automaticPressureDetection = healthSettingInfo.getAutomaticPressureDetection();
                break;
            case AttrAndFunCode.HEALTH_SETTING_TYPE_SLEEP_DETECTION: //睡眠检测
                SleepDetection sleepDetection = healthSettingInfo.getSleepDetection();
                break;
            case AttrAndFunCode.HEALTH_SETTING_TYPE_FALL_DETECTION: //跌倒检测
                FallDetection fallDetection = healthSettingInfo.getFallDetection();
                break;
            case AttrAndFunCode.HEALTH_SETTING_TYPE_LIFT_WRIST_DETECTION: //抬腕检测
                LiftWristDetection liftWristDetection = healthSettingInfo.getLiftWristDetection();
                break;
            case AttrAndFunCode.HEALTH_SETTING_TYPE_USER_INFO: //个人信息
                UserInfo userInfo = healthSettingInfo.getUserInfo();
                break;
            case AttrAndFunCode.HEALTH_SETTING_TYPE_DISCONNECT_REMINDER: //蓝牙断开提醒
                DisconnectReminder disconnectReminder = healthSettingInfo.getDisconnectReminder();
                break;
            case AttrAndFunCode.HEALTH_SETTING_TYPE_BLOOD_OXYGEN_MEASUREMENT_ALERT:  //血氧测量提醒
                BloodOxygenMeasurementAlert bloodOxygenMeasurementAlert = healthSettingInfo.getBloodOxygenMeasurementAlert();
                break;
            case AttrAndFunCode.HEALTH_SETTING_TYPE_EMERGENCY_CONTACT: //紧急联系人
                EmergencyContact emergencyContact = healthSettingInfo.getEmergencyContact();
                break;
        }
    }
});
// mask 设置功能对应的掩码
// 1.获取全部设置
//int mask = 0xffffffff;

// 2.获取部分设置 类型值为:AttrAndFunCode.HEALTH_SETTING_TYPE_XXX,XXX是对应的类型,如获取传感器和睡眠检测,
//查询传感器设置和睡眠检测设置
//3. 不同的功能对应不同的Bit位,对应Bit置1,表示查询该功能
int mask = 0x01 << AttrAndFunCode.HEALTH_SETTING_TYPE_SENSOR
            | 0x01 << AttrAndFunCode.HEALTH_SETTING_TYPE_SLEEP_DETECTION;
//执行读取健康设置信息并等待结果回调
healthOp.readHealthSettings(healthOp.getConnectedDevice(), mask, new OnOperationCallback<Boolean>() {
    @Override
    public void onSuccess(Boolean result) {
        //成功回调
        //结果将会在OnRcspEventListener#onHealthSettingChange回调
    }

    @Override
    public void onFailed(BaseError error) {
        //失败回调
        //error - 错误信息
    }
});
//获取缓存的设置状态,使用缓存状态需要先主动获取状态,避免状态不一致,sdk不会自动获取设备的设置状态
HealthSettingInfo healthSettingInfo = healthOp.getRcspOp().getDeviceInfo().getHealthSettingInfo();

9.2. 修改设置状态

//WatchManager是WatchOpImpl的子类,须在1.3配置好sdk
WatchManager watchManager = WatchManager.getInstance();
//初始化健康功能实现
HealthOpImpl healthOp = new HealthOpImpl(watchManager);
//获取缓存的设置状态,使用缓存状态需要先主动获取状态,避免状态不一致,sdk不会自动获取设备的设置状态
HealthSettingInfo healthSettingInfo = watchManager.getDeviceInfo().getHealthSettingInfo();
//举例: 修改蓝牙断开提醒的设置状态
final DisconnectReminder disconnectReminder = healthSettingInfo.getDisconnectReminder();
//进行修改操作
disconnectReminder.setEnable(false);
//执行配置健康设置信息功能并等待结果回调
healthOp.configHealthSettings(healthOp.getConnectedDevice(), disconnectReminder, new OnOperationCallback<Boolean>() {
    @Override
    public void onSuccess(Boolean result) {
        //成功回调
        //修改成功后,可以重新读取健康设置信息
        //int mask = 1 << disconnectReminder.toAttr().getType();
        //healthOp.readHealthSettings(healthOp.getConnectedDevice(), mask, null);
    }

    @Override
    public void onFailed(BaseError error) {
        //失败回调
        //error - 错误信息
    }
});

9.3. 设置项说明

设置

标识

数据模型

可设置项

传感器功能

0x01

SensorInfo

计步传感器、心率传感器、血氧传感器、海拔气压传感器
通过SensorInfo的getXXX() 方法获取传感器实例<
开关状态enable: false:关闭 、true:打开
记录开关状态recordEnable: false:关闭 、true:打开

久坐提醒

0x02

SedentaryReminder

开关状态enable: false:关闭 、true:打开
提醒模式mode: 0x00:亮屏、 0x01:震动
午休免打扰freeLunchBreak: 关闭/打开(午休时段为12:00-14:00)<
开始时间:startHour, startMin
结束时间:endHour, endMin

连续测量心率

0x03

HeartRateMeasure

开关状态enable: false:关闭 、true:打开
提醒模式mode: 0x00:智能、 0x01: 实时

运动心率提醒

0x04

ExerciseHeartRateReminder

开关状态enable: false:关闭 、true:打开
上限心率max:(0-255)
心率区间划分方式spaceMode: 0x00:最大心率百分比、0x01:存储心率百分比

压力自动检测

0x05

AutomaticPressureDetection

开关状态enable: false:关闭 、true:打开
模式mode: 0 : 放松、1: 正常、2: 中等、3: 偏高

睡眠检测

0x06

SleepDetection

状态status: 0x00:关闭、0x01:全天开启、0x02 自定义时间段
开始时间:startHour, startMin
结束时间:endHour, endMin

跌倒检测

0x07

FallDetection

开关状态enable: false:关闭 、true:打开
提醒模式mode: 0x00:亮屏、 0x01:震动 、 0x02:电话呼叫
电话号码: mobile

抬腕检测

0x08

LiftWristDetection

状态status: 0x00:关闭、0x01:全天开启、0x02 自定义时间段<
提醒模式mode: 0x00:亮屏、 0x01:震动
开始时间:startHour, startMin
结束时间:endHour, endMin

个人信息

0x09

UserInfo

身高:height, 单位: cm, 取整
体重:weight, 单位: kg, 取整
出生年:birthYear
出生月:birthMonth
出生日:birthDay
性别sex: 0x00:女 0x01:男

蓝牙断开提醒

0x0A

DisconnectReminder

状态status: 0x00:关闭、0x01:开启
提醒模式mode: 0x00:亮屏、 0x01:震动

血氧测量提醒

0x0B

BloodOxygenMeasurementAlert

状态status: 0x00:关闭、0x01:开启
模式mode: 0: 智能模式 1: 定时模式
血氧下限数值limitingValue: 0-100

紧急联系人

0x0C

EmergencyContact

电话号码长度phoneLen
电话号码number

引用常量

public class AttrAndFunCode {
    ...
    //健康设备设置
    public final static int HEALTH_SETTING_TYPE_SENSOR = 0x01;//传感器功能
    public final static int HEALTH_SETTING_TYPE_SEDENTARY_REMINDER = 0x02;//久坐提醒
    public final static int HEALTH_SETTING_TYPE_HEART_RATE_MEASURE = 0x03;//连续测量心率
    public final static int HEALTH_SETTING_TYPE_EXERCISE_HEART_RATE_REMINDER = 0x04;//运动心率提醒
    public final static int HEALTH_SETTING_TYPE_AUTOMATIC_PRESSURE_DETECTION = 0x05;//压力自动检测
    public final static int HEALTH_SETTING_TYPE_SLEEP_DETECTION = 0x06;//睡眠检测
    public final static int HEALTH_SETTING_TYPE_FALL_DETECTION = 0x07;//跌倒检测
    public final static int HEALTH_SETTING_TYPE_LIFT_WRIST_DETECTION = 0x08;//抬腕检测
    public final static int HEALTH_SETTING_TYPE_USER_INFO = 0x09;//个人信息
    public final static int HEALTH_SETTING_TYPE_DISCONNECT_REMINDER = 0x0A;//蓝牙断开提醒
    public final static int HEALTH_SETTING_TYPE_BLOOD_OXYGEN_MEASUREMENT_ALERT = 0x0B; //血氧测量提醒
    public final static int HEALTH_SETTING_TYPE_EMERGENCY_CONTACT = 0x0C; //紧急联系人
    ...
}