public class CategoryBodyAgent extends SensorAgent<CategoryBody,CategoryBodyData,ICategoryBodyDataCallback>
SensorAgent and manages body sensors on hardware devices.
This class is used to obtain all body sensors, a type of sensors in the body sensor category, and the first sensor of a specific type, and set or release the sensor data callback.
When you need to obtain the health data such as the heart rate, you can call this class to obtain a specific sensor and set the sensor data callback. You can also release the sensor data callback when the sensor data is unneeded.
SensorBase,
SensorAgent,
CategoryBody,
CategoryBodyData,
ICategoryBodyDataCallbackSystemCapability.Sensors#SENSORSENSOR_CATEGORY_BODY, SENSOR_CATEGORY_DEVICEMOTION, SENSOR_CATEGORY_ENVIRONMENT, SENSOR_CATEGORY_LIGHT, SENSOR_CATEGORY_ORIENTATION, SENSOR_CATEGORY_OTHER, SENSOR_SAMPLING_RATE_FASTEST, SENSOR_SAMPLING_RATE_GAME, SENSOR_SAMPLING_RATE_NORMAL, SENSOR_SAMPLING_RATE_UI, STRING_SENSOR_CATEGORY_BODY, STRING_SENSOR_CATEGORY_DEVICEMOTION, STRING_SENSOR_CATEGORY_ENVIRONMENT, STRING_SENSOR_CATEGORY_LIGHT, STRING_SENSOR_CATEGORY_ORIENTATION, STRING_SENSOR_CATEGORY_OTHER| 构造器 | 说明 |
|---|---|
CategoryBodyAgent() |
Default constructor used to create a
CategoryBodyAgent instance. |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
List<CategoryBody> |
getAllSensors() |
Obtains all body sensors.
|
List<CategoryBody> |
getAllSensors(int sensorType) |
Obtains a specified type of sensors in the body category.
|
CategoryBody |
getSingleSensor(int sensorType) |
Obtains the default sensor of a specified type in the body category.
|
boolean |
releaseSensorDataCallback(ICategoryBodyDataCallback callback) |
Releases the callback for all body sensors.
|
boolean |
releaseSensorDataCallback(ICategoryBodyDataCallback callback,
CategoryBody sensor) |
Releases the callback for a body sensor.
|
boolean |
setSensorDataCallback(ICategoryBodyDataCallback callback,
CategoryBody sensor,
int mode) |
Sets a callback for a body sensor to receive sensor data in a specified sampling mode.
|
boolean |
setSensorDataCallback(ICategoryBodyDataCallback callback,
CategoryBody sensor,
int mode,
long maxDelay) |
Sets a callback for a body sensor to receive sensor data in a specified sampling mode
based on the maximum event reporting latency.
|
boolean |
setSensorDataCallback(ICategoryBodyDataCallback callback,
CategoryBody sensor,
long interval) |
Sets a callback for a body sensor to receive the sensor data at a specified sampling
interval.
|
boolean |
setSensorDataCallback(ICategoryBodyDataCallback callback,
CategoryBody sensor,
long interval,
long maxDelay) |
Sets a callback for a body sensor to receive the sensor data at a specified sampling
interval based on the maximum event reporting latency.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetSensorMinSampleInterval, runCommand, subscribeParamsCheckpublic CategoryBodyAgent()
CategoryBodyAgent instance.public List<CategoryBody> getAllSensors()
Body sensors in this version include only heart rate sensors.
getAllSensors 在类中 SensorAgent<CategoryBody,CategoryBodyData,ICategoryBodyDataCallback>getAllSensors(int),
getSingleSensor(int),
CategoryBodypublic List<CategoryBody> getAllSensors(int sensorType)
getAllSensors 在类中 SensorAgent<CategoryBody,CategoryBodyData,ICategoryBodyDataCallback>sensorType - Indicates a sensor type in the body category.
CategoryBody defines the sensor types using integer
constants. For example, you can set CategoryBody.SENSOR_TYPE_HEART_RATE for this
parameter to obtain heart rate sensors.getAllSensors(),
getSingleSensor(int),
CategoryBodypublic CategoryBody getSingleSensor(int sensorType)
The default sensor is the first sensor of a specified type in the body category.
getSingleSensor 在类中 SensorAgent<CategoryBody,CategoryBodyData,ICategoryBodyDataCallback>sensorType - Indicates a sensor type in the body category.
CategoryBody defines the sensor types using integer
constants. For example, you can set CategoryBody.SENSOR_TYPE_HEART_RATE for this
parameter to obtain heart rate sensors.null if the specified sensor type does
not exist.getAllSensors(),
getAllSensors(int),
CategoryBodypublic boolean setSensorDataCallback(ICategoryBodyDataCallback callback, CategoryBody sensor, long interval)
callback - Indicates the callback
ICategoryBodyDataCallback to set for receiving body
sensor data. If this parameter is null, setting the callback fails.sensor - Indicates the sensor for which the callback is to be set. If this parameter
is null, setting the callback fails.interval - Indicates the sampling interval, in nanoseconds. The sampling interval may
vary depending on the sensor type. You can use the
SensorBase.getMinInterval() and
SensorBase.getMaxInterval() methods to obtain the minimum
sampling interval and maximum sampling interval of the sensor, respectively, and then set
the value of this parameter in between. If the configured parameter value is smaller than
the minimum sampling interval of the sensor, the minimum sampling interval is used. If the
configured parameter value is larger than the maximum sampling interval of the sensor, the
maximum sampling interval is used.true if the callback is set successfully; returns false
otherwise.setSensorDataCallback(ICategoryBodyDataCallback, CategoryBody, long, long),
ICategoryBodyDataCallback,
CategoryBodypublic boolean setSensorDataCallback(ICategoryBodyDataCallback callback, CategoryBody sensor, long interval, long maxDelay)
setSensorDataCallback 在类中 SensorAgent<CategoryBody,CategoryBodyData,ICategoryBodyDataCallback>callback - Indicates the callback
ICategoryBodyDataCallback to set for receiving body
sensor data. If this parameter is null, setting the callback fails.sensor - Indicates the sensor for which the callback is to be set. If this parameter
is null, setting the callback fails.interval - Indicates the sampling interval, in nanoseconds. The sampling interval may
vary depending on the sensor type. You can use the
SensorBase.getMinInterval() and
SensorBase.getMaxInterval() methods to obtain the minimum
sampling interval and maximum sampling interval of the sensor, respectively, and then set
the value of this parameter in between. If the configured parameter value is smaller than
the minimum sampling interval of the sensor, the minimum sampling interval is used. If the
configured parameter value is larger than the maximum sampling interval of the sensor, the
maximum sampling interval is used.maxDelay - Indicates the maximum latency for the sensor to report events to the
application in nanoseconds, based on the first in first out (FIFO) policy of the hardware.
The maximum latency may vary depending on the sensor.true if the callback is set successfully; returns false
otherwise.ICategoryBodyDataCallback,
CategoryBodypublic boolean setSensorDataCallback(ICategoryBodyDataCallback callback, CategoryBody sensor, int mode)
setSensorDataCallback 在类中 SensorAgent<CategoryBody,CategoryBodyData,ICategoryBodyDataCallback>callback - Indicates the callback
ICategoryBodyDataCallback to set for receiving body sensor
data. If this parameter is null, setting the callback fails.sensor - Indicates the sensor for which the callback is to be set. If this parameter
is null, setting the callback fails.mode - Indicates the sampling mode. Each sampling mode represents a sampling rate,
including the fastest sampling rate, sampling rate in gaming scenarios, sampling rate on
UIs, and default sampling rate. For example, you can set the fastest sampling rate of the
sensor via SensorAgent#SENSOR_SAMPLING_RATE_FASTEST.true if the callback is set successfully; returns false
otherwise.public boolean setSensorDataCallback(ICategoryBodyDataCallback callback, CategoryBody sensor, int mode, long maxDelay)
setSensorDataCallback 在类中 SensorAgent<CategoryBody,CategoryBodyData,ICategoryBodyDataCallback>callback - Indicates the callback
ICategoryBodyDataCallback to set for receiving body sensor
data. If this parameter is null, setting the callback fails.sensor - Indicates the sensor for which the callback is to be set. If this parameter
is null, setting the callback fails.mode - Indicates the sampling mode. Each sampling mode represents a sampling rate,
including the fastest sampling rate, sampling rate in gaming scenarios, sampling rate on
UIs, and default sampling rate. For example, you can set the fastest sampling rate of the
sensor via SensorAgent#SENSOR_SAMPLING_RATE_FASTEST.maxDelay - Indicates the maximum latency (in nanoseconds) for the sensor to report
events to the application, based on the first in first out (FIFO) policy of the hardware.
The maximum latency may vary depending on the sensor.true if the callback is set successfully; returns false
otherwise.public boolean releaseSensorDataCallback(ICategoryBodyDataCallback callback, CategoryBody sensor)
releaseSensorDataCallback 在类中 SensorAgent<CategoryBody,CategoryBodyData,ICategoryBodyDataCallback>callback - Indicates the callback
ICategoryBodyDataCallback set for receiving body sensor
data. If this parameter is null, releasing the callback fails.sensor - Indicates the sensor for which the callback is to be released. If this
parameter is null, the callback of all body sensors will be released.true if the callback is released successfully; returns false
otherwise.ICategoryBodyDataCallback,
CategoryBodypublic boolean releaseSensorDataCallback(ICategoryBodyDataCallback callback)
releaseSensorDataCallback 在类中 SensorAgent<CategoryBody,CategoryBodyData,ICategoryBodyDataCallback>callback - Indicates the callback
ICategoryBodyDataCallback set for receiving body sensor
data. If this parameter is null, releasing the callback fails.true if the callback is released successfully; returns false
otherwise.ICategoryBodyDataCallback