The information below concerns legacy mobile tests that work with mobile devices connected to the local computer. For new mobile tests, we recommend using the newer cloud-compatible approach. |
Description
Returns the type of the selected sensor. See Getting Data From Mobile Device Sensors (Legacy).
Note: | For detailed information on built-in sensors, see the documents from the Sensors Overview section of the Android Developer documentation. |
Declaration
AndroidSensorObj.Type
Read-Only Property | String |
AndroidSensorObj | An expression, variable or parameter that specifies a reference to an AndroidSensor object |
Applies To
The property is applied to the following object:
Property Value
A string constant describing the type of the sensor:
Constant value | Description | Number of returned values | Measurement unit |
---|---|---|---|
TYPE_ACCELEROMETER | Measures the acceleration force that is applied to a device on all three physical axes (x, y, and z), including the force of gravity. | 3 | Meters per second squared (m/s2) |
TYPE_AMBIENT_TEMPERATURE | Measures the ambient room temperature. | 1 | Celsius degrees (°C) |
TYPE_GRAVITY | Measures the force of gravity that is applied to a device on all three physical axes (x, y, z). | 3 | Meters per second squared (m/s2) |
TYPE_GYROSCOPE | Measures a device's rate of rotation around each of the three physical axes (x, y, and z). | 3 | Radians per second (rad/s) |
TYPE_LIGHT | Measures the ambient light level. | 1 | Luxes (lx) |
TYPE_LINEAR_ACCELERATION | Measures the acceleration force that is applied to a device on all three physical axes (x, y, and z), excluding the force of gravity. | 3 | Meters per second squared (m/s2) |
TYPE_MAGNETIC_FIELD | Measures the ambient geomagnetic field for all three physical axes (x, y, z). | 3 | Micro-teslas (μT) |
TYPE_ORIENTATION | Measures the rotation that a device makes around all three physical axes (x, y, z). | 3 | Degrees (°) |
TYPE_PRESSURE | Measures the ambient air pressure. | 1 | Milli-bars (mPa) |
TYPE_PROXIMITY | Measures the proximity of an object relative to the view screen of a device. | 1 | Centimeters (cm) |
TYPE_RELATIVE_HUMIDITY | Measures the relative ambient humidity. | 1 | Percents (%) |
TYPE_ROTATION_VECTOR | Measures the orientation of a device by providing the three elements of the device's rotation vector. | 3 | (Unitless) |
TYPE_TEMPERATURE | Measures the temperature of the device. | 1 | Celsius degrees (°C) |
Example
The script below demonstrates how you can list Android device sensors and their values.
JavaScript, JScript
function ListSensors()
{
var sensor, i;
Mobile.SetCurrent("Nexus 7");
for (i = 0; i < Mobile.Device().SensorsCount; i++)
{
sensor = Mobile.Device().Sensor(i);
Log.AppendFolder("Sensor " + i + ": " + sensor.Name);
Log.Message(sensor.Type);
Log.Message("Value0: " + sensor.Values.Value0);
Log.Message("Value1: " + sensor.Values.Value1);
Log.Message("Value2: " + sensor.Values.Value2);
Log.PopLogFolder();
}
}
Python
def ListSensors():
Mobile.SetCurrent("Nexus 7")
for i in range (0, Mobile.Device().SensorsCount):
sensor = Mobile.Device().Sensor[i]
Log.AppendFolder("Sensor " + IntToStr(i) + ": " + sensor.Name)
Log.Message(sensor.Type)
Log.Message("Value0: " + VarToStr(sensor.Values.Value0))
Log.Message("Value1: " + VarToStr(sensor.Values.Value1))
Log.Message("Value2: " + VarToStr(sensor.Values.Value2))
Log.PopLogFolder()
VBScript
Sub ListSensors
Dim sensor, i
Call Mobile.SetCurrent("Nexus 7")
For i = 0 To Mobile.Device.SensorsCount - 1
Set sensor = Mobile.Device.Sensor(i)
Call Log.AppendFolder("Sensor " & i & ": " & sensor.Name)
Call Log.Message(sensor.Type)
Call Log.Message("Value0: " & sensor.Values.Value0)
Call Log.Message("Value1: " & sensor.Values.Value1)
Call Log.Message("Value2: " & sensor.Values.Value2)
Call Log.PopLogFolder
Next
End Sub
DelphiScript
procedure ListSensors;
var sensor, i;
begin
Mobile.SetCurrent('Nexus 7');
for i := 0 to Mobile.Device.SensorsCount - 1 do
begin
sensor := Mobile.Device.Sensor(i);
Log.AppendFolder('Sensor ' + aqConvert.VarToStr(i) + ': ' + sensor.Name);
Log.Message(sensor.Type);
Log.Message('Value0: ' + aqConvert.VarToStr(sensor.Values.Value0));
Log.Message('Value1: ' + aqConvert.VarToStr(sensor.Values.Value1));
Log.Message('Value2: ' + aqConvert.VarToStr(sensor.Values.Value2));
Log.PopLogFolder;
end;
end;
C++Script, C#Script
function ListSensors()
{
var sensor, i;
Mobile["SetCurrent"]("Nexus 7");
for (i = 0; i < Mobile["Device"]["SensorsCount"]; i++)
{
sensor = Mobile["Device"]["Sensor"](i);
Log["AppendFolder"]("Sensor " + i + ": " + sensor["Name"]);
Log["Message"](sensor.Type);
Log["Message"]("Value0: " + ["sensor"]["Values"]["Value0"]);
Log["Message"]("Value1: " + ["sensor"]["Values"]["Value1"]);
Log["Message"]("Value2: " + ["sensor"]["Values"]["Value2"]);
Log["PopLogFolder"]();
}
}
See Also
Getting Data From Mobile Device Sensors (Legacy)
AndroidSensor Object
Sensor Property