Sensor Property

Applies to TestComplete 15.63, last modified on April 10, 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.

Description

Provides access to a particular built-in sensor of the mobile device and to its measurements.

You can access this property only if the Android Agent service is installed and running on the device.

To determine the total number of built-in sensors that are available on the device, see the SensorsCount property.

Declaration

AndroidDeviceObj.Sensor(Index)

Read-Only Property An AndroidSensor object
AndroidDeviceObj An expression, variable or parameter that specifies a reference to an AndroidDevice object
Index [in]    Required    Integer    

Applies To

The property is applied to the following object:

Parameters

The property has the following parameter:

Index

The index of the desired built-in sensor. The index ranges from 0 to SensorsCount - 1.

Property Value

The AndroidSensor object that provides information about the specified sensor and its measurements.

Remarks

If the connected mobile device does not have a sensor with the specified index, an error occurs.

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)
SensorsCount Property
AndroidSensor Object
AndroidDevice Object

Highlight search results