AndroidSensorData Object

Applies to TestComplete 15.64, last modified on May 16, 2024
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.


The AndroidSensorData object represents the data that was provided by one of the built-in sensors of the connected mobile device. See Getting Data From Mobile Device Sensors (Legacy).

The AndroidSensorData object is returned by the Values property of the AndroidSensor object.

In order for TestComplete to be able to provide access to sensor data, the following conditions must be met:

Sensor values are retrieved upon initializing the AndroidSensorData object. Once created, the AndroidSensorData object stores the values that were actual at that moment. To update the sensor values, you need to re-initialize the AndroidSensorData object by re-reading the AndroidSensor.Values property. Keep this in mind when exploring the AndroidSensorData object in the Object Browser, as pressing the Refresh All toolbar button does not re-initialize the objects.

The exact number of measured parameters, as well as their measurement units depend on the sensor type. You can read the type of the selected sensor via the AndroidSensor.Type property.

Depending on the sensor type, it can return either 1 or 3 measurements. The AndroidSensorData object always has three properties (Value0, Value1, Value2) reserved for storing measurements. If the selected sensor measures only one parameter, then it is stored in the Value0 property. In this case, the Value1, Value2 properties return zero.


The object contains the following properties:

Note: All the properties are read-only and return a floating point value.
Property Description
Value0 Returns the value with index 0.
Value1 Returns the value with index 1.
Value2 Returns the value with index 2.


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("Value0: " + sensor.Values.Value0);
    Log.Message("Value1: " + sensor.Values.Value1);
    Log.Message("Value2: " + sensor.Values.Value2);


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("Value0: " + VarToStr(sensor.Values.Value0))
    Log.Message("Value1: " + VarToStr(sensor.Values.Value1))
    Log.Message("Value2: " + VarToStr(sensor.Values.Value2))


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
End Sub


procedure ListSensors;
var sensor, i;
  Mobile.SetCurrent('Nexus 7');
  for i := 0 to Mobile.Device.SensorsCount - 1 do
    sensor := Mobile.Device.Sensor(i);
    Log.AppendFolder('Sensor ' + aqConvert.VarToStr(i) + ': ' + sensor.Name);
    Log.Message('Value0: ' + aqConvert.VarToStr(sensor.Values.Value0));
    Log.Message('Value1: ' + aqConvert.VarToStr(sensor.Values.Value1));
    Log.Message('Value2: ' + aqConvert.VarToStr(sensor.Values.Value2));

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"]("Value0: " + ["sensor"]["Values"]["Value0"]);
    Log["Message"]("Value1: " + ["sensor"]["Values"]["Value1"]);
    Log["Message"]("Value2: " + ["sensor"]["Values"]["Value2"]);

See Also

Getting Data From Mobile Device Sensors (Legacy)
AndroidSensor Object
Values Property

Highlight search results