public class CategoryEnvironmentAgent extends SensorAgent<CategoryEnvironment,CategoryEnvironmentData,ICategoryEnvironmentDataCallback>
SensorAgent and manages environment sensors on hardware devices.
This class is used to obtain all environment sensors, a type of sensors in the environment sensor category, and the first sensor of a specific type, and set or release the sensor data callback.
When you need to obtain information such as the temperature, humidity, barometric pressure, and magnetic field, 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,
CategoryEnvironment,
CategoryEnvironmentData,
ICategoryEnvironmentDataCallbackSystemCapability.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| 构造器 | 说明 |
|---|---|
CategoryEnvironmentAgent() |
Default constructor used to create a
CategoryEnvironmentAgent instance. |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
List<CategoryEnvironment> |
getAllSensors() |
Obtains all environment sensors.
|
List<CategoryEnvironment> |
getAllSensors(int sensorType) |
Obtains a specified type of sensors in the environment category.
|
CategoryEnvironment |
getSingleSensor(int sensorType) |
Obtains the default sensor of a specified type in the environment category.
|
boolean |
releaseSensorDataCallback(ICategoryEnvironmentDataCallback callback) |
Releases the callback for all environment sensors.
|
boolean |
releaseSensorDataCallback(ICategoryEnvironmentDataCallback callback,
CategoryEnvironment sensor) |
Releases the callback for an environment sensor.
|
boolean |
setSensorDataCallback(ICategoryEnvironmentDataCallback callback,
CategoryEnvironment sensor,
int mode) |
Sets a callback for an environment sensor to receive sensor data in a specified sampling
mode.
|
boolean |
setSensorDataCallback(ICategoryEnvironmentDataCallback callback,
CategoryEnvironment sensor,
int mode,
long maxDelay) |
Sets a callback for an environment sensor to receive sensor data in a specified sampling
mode based on the maximum event reporting latency.
|
boolean |
setSensorDataCallback(ICategoryEnvironmentDataCallback callback,
CategoryEnvironment sensor,
long interval) |
Sets a callback for an environment sensor to receive the sensor data at a specified
sampling interval.
|
boolean |
setSensorDataCallback(ICategoryEnvironmentDataCallback callback,
CategoryEnvironment sensor,
long interval,
long maxDelay) |
Sets a callback for an environment 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 CategoryEnvironmentAgent()
CategoryEnvironmentAgent instance.public List<CategoryEnvironment> getAllSensors()
Environment sensors include temperature sensors, magnetic field sensors, uncalibrated magnetic field sensors, humidity sensors, barometers, and Specific Absorption Rate (SAR) sensors.
getAllSensors 在类中 SensorAgent<CategoryEnvironment,CategoryEnvironmentData,ICategoryEnvironmentDataCallback>getAllSensors(int),
getSingleSensor(int),
CategoryEnvironmentpublic List<CategoryEnvironment> getAllSensors(int sensorType)
getAllSensors 在类中 SensorAgent<CategoryEnvironment,CategoryEnvironmentData,ICategoryEnvironmentDataCallback>sensorType - Indicates a sensor type in the environment category.
CategoryEnvironment defines the sensor types using integer
constants. For example, you can set CategoryEnvironment.SENSOR_TYPE_MAGNETIC_FIELD
for this parameter to obtain magnetic field sensors.getAllSensors(),
getSingleSensor(int),
CategoryEnvironmentpublic CategoryEnvironment getSingleSensor(int sensorType)
The default sensor is the first sensor of a specified type in the environment category.
getSingleSensor 在类中 SensorAgent<CategoryEnvironment,CategoryEnvironmentData,ICategoryEnvironmentDataCallback>sensorType - Indicates a sensor type in the environment category.
CategoryEnvironment defines the sensor types using integer
constants. For example, you can set CategoryEnvironment.SENSOR_TYPE_MAGNETIC_FIELD
for this parameter to obtain magnetic field sensors.null if the specified sensor
type does not exist.getAllSensors(),
getAllSensors(int),
CategoryEnvironmentpublic boolean setSensorDataCallback(ICategoryEnvironmentDataCallback callback, CategoryEnvironment sensor, long interval)
callback - Indicates the callback
ICategoryEnvironmentDataCallback to set for receiving
environment 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(ICategoryEnvironmentDataCallback, CategoryEnvironment, long, long),
ICategoryEnvironmentDataCallback,
CategoryEnvironmentpublic boolean setSensorDataCallback(ICategoryEnvironmentDataCallback callback, CategoryEnvironment sensor, long interval, long maxDelay)
setSensorDataCallback 在类中 SensorAgent<CategoryEnvironment,CategoryEnvironmentData,ICategoryEnvironmentDataCallback>callback - Indicates the callback
ICategoryEnvironmentDataCallback to set for receiving
environment 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.ICategoryEnvironmentDataCallback,
CategoryEnvironmentpublic boolean setSensorDataCallback(ICategoryEnvironmentDataCallback callback, CategoryEnvironment sensor, int mode)
setSensorDataCallback 在类中 SensorAgent<CategoryEnvironment,CategoryEnvironmentData,ICategoryEnvironmentDataCallback>callback - Indicates the callback
ICategoryEnvironmentDataCallback to set for receiving
environment 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(ICategoryEnvironmentDataCallback callback, CategoryEnvironment sensor, int mode, long maxDelay)
setSensorDataCallback 在类中 SensorAgent<CategoryEnvironment,CategoryEnvironmentData,ICategoryEnvironmentDataCallback>callback - Indicates the callback
ICategoryEnvironmentDataCallback to set for receiving
environment 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(ICategoryEnvironmentDataCallback callback, CategoryEnvironment sensor)
releaseSensorDataCallback 在类中 SensorAgent<CategoryEnvironment,CategoryEnvironmentData,ICategoryEnvironmentDataCallback>callback - Indicates the callback
ICategoryEnvironmentDataCallback set for receiving
environment 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 environment sensors will be released.true if the callback is released successfully; returns false
otherwise.ICategoryEnvironmentDataCallback,
CategoryEnvironmentpublic boolean releaseSensorDataCallback(ICategoryEnvironmentDataCallback callback)
releaseSensorDataCallback 在类中 SensorAgent<CategoryEnvironment,CategoryEnvironmentData,ICategoryEnvironmentDataCallback>callback - Indicates the callback
ICategoryEnvironmentDataCallback set for receiving
environment sensor data. If this parameter is null, releasing the callback fails.true if the callback is released successfully; returns false
otherwise.ICategoryEnvironmentDataCallback