The following sensor functionality is provided:
For more information about how to use Sensor API, see Sensor Guide.
Since: 2.3
enum SensorType { "LIGHT", "MAGNETIC", "PRESSURE", "PROXIMITY", "ULTRAVIOLET", "HRM_RAW" };
Since: 2.3
The sensor types defined by this enumerator are:
Remark : HRM_RAW is supported since Tizen 2.3.1
[NoInterfaceObject] interface SensorServiceManagerObject { readonly attribute SensorService sensorservice; };
Tizen implements SensorServiceManagerObject;
Since: 2.3
[NoInterfaceObject] interface SensorService { Sensor getDefaultSensor(SensorType type) raises(WebAPIException); SensorType[] getAvailableSensors() raises(WebAPIException); };
Since: 2.3
getDefaultSensor
Sensor getDefaultSensor(SensorType type);
Since: 2.3
The supported sensor types are hardware-dependent.
To check if the given type is supported or not, SystemInfo API can be used.
Privilege level: public
Privilege: http://tizen.org/privilege/healthinfo
Remark : http://tizen.org/privilege/healthinfo is required only for HRM_RAW type. HRM_RAW is supported since Tizen 2.3.1
Parameters:
Return value:
Sensor Default sensor objectExceptions:
with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter.
with error type UnknownError, if accessing a given sensor type fails because of an unknown error.
with error type NotSupportedError, if the given type is not supported on the device.
with error type SecurityError, this error is only thrown for HRM_RAW sensor type when an application does not have http://tizen.org/privilege/healthinfo privilege in config.xml.
Code example:
var proximityCapability = tizen.systeminfo.getCapability("http://tizen.org/feature/sensor.proximity"); if (proximityCapability === true) { // the device supports proximity sensor and you can get proximity sensor's data var proximitySensor = tizen.sensorservice.getDefaultSensor("PROXIMITY"); } else { // If tizen.sensorservice.getDefaultSensor("PROXIMITY") is used, NotSupportedError would be thrown. console.log("Proximity sensor is not supported on this device."); }
getAvailableSensors
SensorType[] getAvailableSensors();
Since: 2.3
Return value:
SensorType[] All available sensor typesExceptions:
with error type UnknownError, if getting available sensor type fails because of an unknown error.
Code example:
var sensorCapabilities = tizen.sensorservice.getAvailableSensors(); console.log("capable sensor : " + sensorCapabilities[0]);
[NoInterfaceObject] interface Sensor { readonly attribute SensorType sensorType; void start(SuccessCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void stop() raises(WebAPIException); void setChangeListener(SensorDataSuccessCallback successCallback) raises(WebAPIException); void unsetChangeListener() raises(WebAPIException); };
Since: 2.3
Since: 2.3
start
void start(SuccessCallback successCallback, optional ErrorCallback? errorCallback);
Since: 2.3
Parameters:
Exceptions:
with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter.
with error type UnknownError, if starting the sensor fails because of an unknown error.
Code example:
var proximitySensor = tizen.sensorservice.getDefaultSensor("PROXIMITY"); function onsuccessCB() { console.log("The proximity sensor started successfully."); } proximitySensor.start(onsuccessCB);
stop
void stop();
Since: 2.3
Exceptions:
with error type UnknownError, if stopping the sensor fails because of an unknown error.
Code example:
var proximitySensor = tizen.sensorservice.getDefaultSensor("PROXIMITY"); function onsuccessCB() { console.log("proximity sensor start"); proximitySensor.stop(); } proximitySensor.start(onsuccessCB);
setChangeListener
void setChangeListener(SensorDataSuccessCallback successCallback);
Since: 2.3
Note that the setChangeListener() method only registers the listener. The start() method must be called to turn on the sensor, or the sensor data will not change.
Parameters:
Exceptions:
with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter.
with error type UnknownError, if registering the listener fails because of an unknown error.
Code example:
var proximitySensor = tizen.sensorservice.getDefaultSensor("PROXIMITY"); function onsuccessCB() { console.log("proximity sensor start"); } function onchangedCB(sensorData) { console.log("proximity distance : " + sensorData.proximityState); } proximitySensor.setChangeListener(onchangedCB); proximitySensor.start(onsuccessCB);
unsetChangeListener
void unsetChangeListener();
Since: 2.3
Exceptions:
with error type UnknownError, if unregistering the listener fails because of an unknown error.
Code example:
var proximitySensor = tizen.sensorservice.getDefaultSensor("PROXIMITY"); function onchangedCB(sensorData) { console.log("proximity distance : " + sensorData.proximityState); } proximitySensor.setChangeListener(onchangedCB); proximitySensor.unsetChangeListener();
[NoInterfaceObject] interface LightSensor : Sensor { void getLightSensorData(SensorDataSuccessCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); };
Since: 2.3
getLightSensorData
void getLightSensorData(SensorDataSuccessCallback successCallback, optional ErrorCallback? errorCallback);
Since: 2.3
Note that before calling the getLightSensorData() method, the start() method should be called to turn on the sensor.
The ErrorCallback method is launched with these error types:
Parameters:
Exceptions:
with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter.
Code example:
var lightSensor = tizen.sensorservice.getDefaultSensor("LIGHT"); function onGetSuccessCB(sensorData) { console.log("light level : " + sensorData.lightLevel); } function onerrorCB(error) { console.log("error occurs"); } function onsuccessCB() { console.log("sensor start"); lightSensor.getLightSensorData(onGetSuccessCB, onerrorCB); } lightSensor.start(onsuccessCB);
[NoInterfaceObject] interface MagneticSensor : Sensor { void getMagneticSensorData(SensorDataSuccessCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); };
Since: 2.3
getMagneticSensorData
void getMagneticSensorData(SensorDataSuccessCallback successCallback, optional ErrorCallback? errorCallback);
Since: 2.3
Note that before calling the getMagneticSensorData() method, the start() method should be called to turn on the sensor.
The ErrorCallback method is launched with these error types:
Parameters:
Exceptions:
with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter.
Code example:
var magneticSensor = tizen.sensorservice.getDefaultSensor("MAGNETIC"); function onGetSuccessCB(sensorData) { console.log("magnetic field of the X axis : " + sensorData.x); console.log("magnetic field of the Y axis : " + sensorData.y); console.log("magnetic field of the Z axis : " + sensorData.z); } function onerrorCB(error) { console.log("error occurs"); } function onsuccessCB() { console.log("sensor start"); magneticSensor.getMagneticSensorData(onGetSuccessCB, onerrorCB); } magneticSensor.start(onsuccessCB);
[NoInterfaceObject] interface PressureSensor : Sensor { void getPressureSensorData(SensorDataSuccessCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); };
Since: 2.3
getPressureSensorData
void getPressureSensorData(SensorDataSuccessCallback successCallback, optional ErrorCallback? errorCallback);
Since: 2.3
Note that the start() method should be called before calling the getPressureSensorData() method to turn on the sensor.
The ErrorCallback method is launched with these error types:
Parameters:
Exceptions:
with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter.
Code example:
var pressureSensor = tizen.sensorservice.getDefaultSensor("PRESSURE"); function onGetSuccessCB(sensorData) { console.log("pressure : " + sensorData.pressure); } function onerrorCB(error) { console.log("error occurs"); } function onsuccessCB() { console.log("sensor start"); pressureSensor.getPressureSensorData(onGetSuccessCB, onerrorCB); } pressureSensor.start(onsuccessCB);
[NoInterfaceObject] interface ProximitySensor : Sensor { void getProximitySensorData(SensorDataSuccessCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); };
Since: 2.3
getProximitySensorData
void getProximitySensorData(SensorDataSuccessCallback successCallback, optional ErrorCallback? errorCallback);
Since: 2.3
Note that before calling the getProximitySensorData() method, the start() method should be called to turn on the sensor.
The ErrorCallback method is launched with these error types:
Parameters:
Exceptions:
with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter.
Code example:
var proximitySensor = tizen.sensorservice.getDefaultSensor("PROXIMITY"); function onGetSuccessCB(sensorData) { console.log("proximity state : " + sensorData.proximityState); } function onerrorCB(error) { console.log("error occurs"); } function onsuccessCB() { console.log("proximity sensor start"); proximitySensor.getProximitySensorData(onGetSuccessCB, onerrorCB); } proximitySensor.start(onsuccessCB);
[NoInterfaceObject] interface UltravioletSensor : Sensor { void getUltravioletSensorData(SensorDataSuccessCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); };
Since: 2.3
getUltravioletSensorData
void getUltravioletSensorData(SensorDataSuccessCallback successCallback, optional ErrorCallback? errorCallback);
Since: 2.3
Note that before calling the getUltravioletSensorData() method, the start() method should be called to turn on the sensor.
The ErrorCallback method is launched with these error types:
Parameters:
Exceptions:
with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter.
Code example:
var ultravioletSensor = tizen.sensorservice.getDefaultSensor("ULTRAVIOLET"); function onGetSuccessCB(sensorData) { console.log("ultraviolet level : " + sensorData.ultravioletLevel); } function onerrorCB(error) { console.log("error occurs"); } function onsuccessCB() { console.log("ultraviolet sensor start"); ultravioletSensor.getUltravioletSensorData(onGetSuccessCB, onerrorCB); } ultravioletSensor.start(onsuccessCB);
[NoInterfaceObject] interface HRMRawSensor : Sensor { void getHRMRawSensorData(SensorDataSuccessCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); };
Since: 2.3.1
getHRMRawSensorData
void getHRMRawSensorData(SensorDataSuccessCallback successCallback, optional ErrorCallback? errorCallback);
Since: 2.3.1
Note that before calling the getHRMRawSensorData() method, the start() method should be called to turn on the sensor.
The ErrorCallback method is launched with these error types:
Privilege level: public
Privilege: http://tizen.org/privilege/healthinfo
Parameters:
Exceptions:
with error type TypeMismatchError, if any input parameter is not compatible with the expected type for that parameter.
with error type UnknownError, if retrieving the sensor data fails because of an unknown error.
with error type SecurityError, if the application does not have the privilege to use this function.
Code example:
var HRMrawsensor = tizen.sensorservice.getDefaultSensor("HRM_RAW"); function onGetSuccessCB(sensorData) { console.log("HRMRaw light intensity : " + sensorData.lightIntensity); } function onerrorCB(error) { console.log("error occurs"); } function onsuccessCB() { console.log("HRMRaw sensor start"); HRMrawsensor.getHRMRawSensorData(onGetSuccessCB, onerrorCB); } HRMrawsensor.start(onsuccessCB);
[NoInterfaceObject] interface SensorData { };
Since: 2.3
[NoInterfaceObject] interface SensorLightData : SensorData { readonly attribute double lightLevel; };
Since: 2.3
Since: 2.3
[NoInterfaceObject] interface SensorMagneticData : SensorData { readonly attribute double x; readonly attribute double y; readonly attribute double z; readonly attribute MagneticSensorAccuracy accuracy; };
Since: 2.3
Since: 2.3
Since: 2.3
Since: 2.3
For increasing the accuracy, wave the device around in the air in figure-eight patterns.
Since: 2.3
[NoInterfaceObject] interface SensorPressureData : SensorData { readonly attribute double pressure; };
Since: 2.3
Since: 2.3
[NoInterfaceObject] interface SensorProximityData : SensorData { readonly attribute ProximityState proximityState; };
Since: 2.3
Since: 2.3
[NoInterfaceObject] interface SensorUltravioletData : SensorData { readonly attribute long ultravioletLevel; };
Since: 2.3
The ultraviolet index is an international standard measurement of the strength of ultraviolet radiation from the sun. The ultravioletLevel ranges from 0 to 15.
Since: 2.3
[NoInterfaceObject] interface SensorHRMRawData : SensorData { readonly attribute DOMString lightType; readonly attribute unsigned long lightIntensity; };
Since: 2.3.1
The following values are supported:
Since: 2.3.1
Since: 2.3.1
[Callback=FunctionOnly, NoInterfaceObject] interface SensorDataSuccessCallback { void onsuccess(optional SensorData? sensorData); };
Since: 2.3
onsuccess
void onsuccess(optional SensorData? sensorData);
Since: 2.3
Parameters:
To guarantee that the light sensor application runs on a device with a photometer (light) sensor, declare the following feature requirement in the config file:
To guarantee that the magnetic sensor application runs on a device with a magnetic sensor, declare the following feature requirement in the config file:
To guarantee that the barometer(pressure) sensor application runs on a device with a barometric (pressure) sensor, declare the following feature requirement in the config file:
To guarantee that the proximity sensor application runs on a device with a proximity sensor, declare the following feature requirement in the config file:
To guarantee that the UV sensor application runs on a device with a UV sensor, declare the following feature requirement in the config file:
To guarantee that the Heart Rate Monitor application runs on a device with a heart rate monitor, declare the following feature requirements in the config file:
module Sensor { enum SensorType { "LIGHT", "MAGNETIC", "PRESSURE", "PROXIMITY", "ULTRAVIOLET", "HRM_RAW" }; enum ProximityState { "FAR", "NEAR" }; enum MagneticSensorAccuracy { "ACCURACY_UNDEFINED", "ACCURACY_BAD", "ACCURACY_NORMAL", "ACCURACY_GOOD", "ACCURACY_VERYGOOD" }; [NoInterfaceObject] interface SensorServiceManagerObject { readonly attribute SensorService sensorservice; }; Tizen implements SensorServiceManagerObject; [NoInterfaceObject] interface SensorService { Sensor getDefaultSensor(SensorType type) raises(WebAPIException); SensorType[] getAvailableSensors() raises(WebAPIException); }; [NoInterfaceObject] interface Sensor { readonly attribute SensorType sensorType; void start(SuccessCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); void stop() raises(WebAPIException); void setChangeListener(SensorDataSuccessCallback successCallback) raises(WebAPIException); void unsetChangeListener() raises(WebAPIException); }; [NoInterfaceObject] interface LightSensor : Sensor { void getLightSensorData(SensorDataSuccessCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); }; [NoInterfaceObject] interface MagneticSensor : Sensor { void getMagneticSensorData(SensorDataSuccessCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); }; [NoInterfaceObject] interface PressureSensor : Sensor { void getPressureSensorData(SensorDataSuccessCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); }; [NoInterfaceObject] interface ProximitySensor : Sensor { void getProximitySensorData(SensorDataSuccessCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); }; [NoInterfaceObject] interface UltravioletSensor : Sensor { void getUltravioletSensorData(SensorDataSuccessCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); }; [NoInterfaceObject] interface HRMRawSensor : Sensor { void getHRMRawSensorData(SensorDataSuccessCallback successCallback, optional ErrorCallback? errorCallback) raises(WebAPIException); }; [NoInterfaceObject] interface SensorData { }; [NoInterfaceObject] interface SensorLightData : SensorData { readonly attribute double lightLevel; }; [NoInterfaceObject] interface SensorMagneticData : SensorData { readonly attribute double x; readonly attribute double y; readonly attribute double z; readonly attribute MagneticSensorAccuracy accuracy; }; [NoInterfaceObject] interface SensorPressureData : SensorData { readonly attribute double pressure; }; [NoInterfaceObject] interface SensorProximityData : SensorData { readonly attribute ProximityState proximityState; }; [NoInterfaceObject] interface SensorUltravioletData : SensorData { readonly attribute long ultravioletLevel; }; [NoInterfaceObject] interface SensorHRMRawData : SensorData { readonly attribute DOMString lightType; readonly attribute unsigned long lightIntensity; }; [Callback=FunctionOnly, NoInterfaceObject] interface SensorDataSuccessCallback { void onsuccess(optional SensorData? sensorData); }; };