Values Property

Applies to TestComplete 14.60, last modified on April 22, 2021

Description

Returns the object containing the values generated by the selected sensor.

Declaration

AndroidSensorObj.Values

Read-Only Property An AndroidSensorData object
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

The AndroidSensorData object containing the values generated by the selected sensor at the moment you referred to the object.

Remarks

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 and Value2 properties return zero.

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 AndroidSensorObj.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.

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
AndroidSensor Object
Sensor Property

Highlight search results