public class CategoryLightAgent extends SensorAgent<CategoryLight,CategoryLightData,ICategoryLightDataCallback>
SensorAgent and manages light sensors on hardware devices.
This class is used to obtain all light sensors, a type of sensors in the light 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 proximity, ambient light, and color temperature, 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,
CategoryLight,
CategoryLightData,
ICategoryLightDataCallbackSystemCapability.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| 构造器 | 说明 |
|---|---|
CategoryLightAgent() |
Default constructor used to create a
CategoryLightAgent instance. |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
List<CategoryLight> |
getAllSensors() |
Obtains all light sensors.
|
List<CategoryLight> |
getAllSensors(int sensorType) |
Obtains a specified type of sensors in the light category.
|
CategoryLight |
getSingleSensor(int sensorType) |
Obtains the default sensor of a specified type in the light category.
|
boolean |
releaseSensorDataCallback(ICategoryLightDataCallback callback) |
Releases the callback for all light sensors.
|
boolean |
releaseSensorDataCallback(ICategoryLightDataCallback callback,
CategoryLight sensor) |
Releases the callback for a light sensor.
|
boolean |
setSensorDataCallback(ICategoryLightDataCallback callback,
CategoryLight sensor,
int mode) |
Sets a callback for a light sensor to receive sensor data in a specified sampling mode.
|
boolean |
setSensorDataCallback(ICategoryLightDataCallback callback,
CategoryLight sensor,
int mode,
long maxDelay) |
Sets a callback for a light sensor to receive sensor data in a specified sampling mode
based on the maximum event reporting latency.
|
boolean |
setSensorDataCallback(ICategoryLightDataCallback callback,
CategoryLight sensor,
long interval) |
Sets a callback for a light sensor to receive the sensor data at a specified sampling
interval.
|
boolean |
setSensorDataCallback(ICategoryLightDataCallback callback,
CategoryLight sensor,
long interval,
long maxDelay) |
Sets a callback for a light 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 CategoryLightAgent()
CategoryLightAgent instance.public List<CategoryLight> getAllSensors()
Light sensors include proximity sensors, Time of Flight (ToF) sensors, ambient light sensors, color temperature sensors, and color sensors.
getAllSensors 在类中 SensorAgent<CategoryLight,CategoryLightData,ICategoryLightDataCallback>getAllSensors(int),
getSingleSensor(int),
CategoryLightpublic List<CategoryLight> getAllSensors(int sensorType)
getAllSensors 在类中 SensorAgent<CategoryLight,CategoryLightData,ICategoryLightDataCallback>sensorType - Indicates a sensor type in the light category.
CategoryLight defines the sensor types using integer
constants. For example, you can set CategoryLight.SENSOR_TYPE_PROXIMITY for this
parameter to obtain proximity sensors.getAllSensors(),
getSingleSensor(int),
CategoryLightpublic CategoryLight getSingleSensor(int sensorType)
The default sensor is the first sensor of a specified type in the light category.
getSingleSensor 在类中 SensorAgent<CategoryLight,CategoryLightData,ICategoryLightDataCallback>sensorType - Indicates a sensor type in the light category.
CategoryLight defines the sensor types using integer
constants. For example, you can set CategoryLight.SENSOR_TYPE_PROXIMITY for this
parameter to obtain proximity sensors.null if the specified sensor type does
not exist.getAllSensors(),
getAllSensors(int),
CategoryLightpublic boolean setSensorDataCallback(ICategoryLightDataCallback callback, CategoryLight sensor, long interval)
callback - Indicates the callback
ICategoryLightDataCallback to set for receiving light
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(ICategoryLightDataCallback, CategoryLight, long, long),
ICategoryLightDataCallback,
CategoryLightpublic boolean setSensorDataCallback(ICategoryLightDataCallback callback, CategoryLight sensor, long interval, long maxDelay)
setSensorDataCallback 在类中 SensorAgent<CategoryLight,CategoryLightData,ICategoryLightDataCallback>callback - Indicates the callback
ICategoryLightDataCallback to set for receiving light
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.ICategoryLightDataCallback,
CategoryLightpublic boolean setSensorDataCallback(ICategoryLightDataCallback callback, CategoryLight sensor, int mode)
setSensorDataCallback 在类中 SensorAgent<CategoryLight,CategoryLightData,ICategoryLightDataCallback>callback - Indicates the callback
ICategoryLightDataCallback to set for receiving light 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(ICategoryLightDataCallback callback, CategoryLight sensor, int mode, long maxDelay)
setSensorDataCallback 在类中 SensorAgent<CategoryLight,CategoryLightData,ICategoryLightDataCallback>callback - Indicates the callback
ICategoryLightDataCallback to set for receiving light 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(ICategoryLightDataCallback callback, CategoryLight sensor)
releaseSensorDataCallback 在类中 SensorAgent<CategoryLight,CategoryLightData,ICategoryLightDataCallback>callback - Indicates the callback
ICategoryLightDataCallback set for receiving light
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 light sensors will be released.true if the callback is released successfully; returns false
otherwise.ICategoryLightDataCallback,
CategoryLightpublic boolean releaseSensorDataCallback(ICategoryLightDataCallback callback)
releaseSensorDataCallback 在类中 SensorAgent<CategoryLight,CategoryLightData,ICategoryLightDataCallback>callback - Indicates the callback
ICategoryLightDataCallback set for receiving light
sensor data. If this parameter is null, releasing the callback fails.true if the callback is released successfully; returns false
otherwise.ICategoryLightDataCallback