proximity-sensor-plugin
Mobile icon

Proximity Sensor Plugin

Stable version 1.0.0 (Compatible with OutSystems 11)
Uploaded
 on 7 Sep (11 hours ago)
 by 
0.0
 (0 ratings)
proximity-sensor-plugin

Proximity Sensor Plugin

Documentation
1.0.0

1. Overview

Proximity Sensor Plugin is an OutSystems 11 mobile plugin that provides access to the device's proximity sensor.

The component allows mobile applications to:

  • Check whether the proximity sensor is available.
  • Enable the proximity sensor.
  • Disable the proximity sensor.
  • Retrieve the current proximity state.
  • Determine whether an object is near or far from the device's proximity sensor.

The plugin uses the native device capabilities provided through a Cordova proximity sensor plugin.


2. Supported Platforms

The underlying Cordova plugin supports:

  • Android
  • iOS

The component has been tested on Android.

iOS support is provided by the underlying Cordova plugin and should be validated on the target iOS environment before production use.

Note: Proximity sensor availability and behavior can vary depending on the device hardware and operating system.


3. Requirements

This component is intended for:

  • OutSystems 11
  • Mobile applications
  • Physical devices with a supported proximity sensor

The proximity sensor cannot be properly tested using the browser preview because it depends on native device capabilities.


4. Installation

Install Proximity Sensor Plugin from Forge and add it as a dependency to your OutSystems 11 mobile application.

After adding the component, you can use the exposed Client Actions directly from your mobile application logic.

Important

Because this component uses a native mobile plugin, changes to the native plugin configuration require a new mobile application build.

Simply publishing the application logic is not sufficient when the native plugin configuration changes.


5. Available Client Actions

The component provides four Client Actions:

Client ActionPurpose
CheckProximityAvailabilityChecks whether the proximity sensor plugin is available
EnableProximitySensorEnables the proximity sensor
DisableProximitySensorDisables the proximity sensor
GetProximityStateRetrieves the current proximity state

6. CheckProximityAvailability

Description

Checks whether the proximity sensor plugin is available in the current mobile application.

Outputs

IsAvailable — Boolean

  • True — Proximity sensor plugin is available.
  • False — Proximity sensor plugin is not available.

Example

Call:

CheckProximityAvailability

Then check:

IsAvailable = True

before attempting to use the proximity sensor.


7. EnableProximitySensor

Description

Enables the device proximity sensor and starts proximity monitoring.

Outputs

Success — Boolean

Indicates whether the sensor was successfully enabled.

ErrorMessage — Text

Contains the error message when the operation fails.

Example

EnableProximitySensor

Then check:

Success = True

If the operation fails, use:

ErrorMessage

to identify the problem.


8. DisableProximitySensor

Description

Disables the device proximity sensor and stops proximity monitoring.

Outputs

Success — Boolean

Indicates whether the sensor was successfully disabled.

ErrorMessage — Text

Contains the error message when the operation fails.

Example

DisableProximitySensor

Then check:

Success = True

9. GetProximityState

Description

Retrieves the current state of the device's proximity sensor.

Outputs

IsNear — Boolean

  • True — An object is detected near the proximity sensor.
  • False — No object is detected near the proximity sensor.

Success — Boolean

Indicates whether the proximity state was successfully retrieved.

ErrorMessage — Text

Contains the error message when the operation fails.

Example

GetProximityState

Then:

If(IsNear,
    "Object is near",
    "Object is far"
)

10. Recommended Usage Flow

A typical implementation can follow this sequence:

CheckProximityAvailability
          ↓
     IsAvailable?
          ↓
         Yes
          ↓
EnableProximitySensor
          ↓
GetProximityState
          ↓
Use IsNear in application logic
          ↓
DisableProximitySensor

Example

You can implement the following flow:

  1. Check whether the proximity sensor is available.
  2. If available, enable the sensor.
  3. Retrieve the current proximity state when required.
  4. Use IsNear to determine whether an object is near the sensor.
  5. Disable the sensor when proximity monitoring is no longer needed.

11. Monitoring Proximity

GetProximityState returns the current proximity state when it is called.

If your application needs to continuously monitor the sensor, you can call GetProximityState periodically using an OutSystems Timer.

For example:

Timer
  ↓
GetProximityState
  ↓
Update IsNear
  ↓
Repeat

For most use cases, a reasonable polling interval should be selected based on the application's requirements rather than continuously polling at a very high frequency.


12. Understanding the Proximity State

The IsNear output is a Boolean value.

When IsNear = True

An object is detected close to the proximity sensor.

For example:

Hand → 📱
       NEAR

When IsNear = False

No object is detected close to the proximity sensor.

Hand        📱
           FAR

The exact detection distance depends on the device's proximity sensor hardware.


13. Device Behavior

When the proximity sensor detects an object nearby, the device may automatically dim the screen or change screen interaction behavior.

This behavior is controlled by the device's operating system and may vary depending on the device and platform.

This behavior is not controlled by the OutSystems component.


14. Android Testing

The component has been tested on an Android physical device.

The tested flow includes:

  1. Checking proximity sensor availability.
  2. Enabling the proximity sensor.
  3. Placing a hand near the proximity sensor.
  4. Retrieving the proximity state.
  5. Moving the hand away from the sensor.
  6. Retrieving the updated proximity state.
  7. Disabling the proximity sensor.

On the tested Android device, the screen dims when an object is placed near the proximity sensor.


15. iOS Considerations

The underlying Cordova plugin supports iOS.

However, iOS behavior can differ from Android depending on the device and operating system.

On iOS, the proximity sensor can affect screen brightness and touch interaction when the sensor detects a nearby object.

The component has not been independently validated on an iOS physical device, so applications targeting iOS should test the component on their target devices before production deployment.


16. Demo Application

A Proximity Sensor Demo application is included with the component.

The demo demonstrates:

  • Proximity sensor availability
  • Enabling the sensor
  • Disabling the sensor
  • Retrieving the proximity state
  • Displaying whether the sensor detects a nearby object

Testing the Demo

  1. Install the demo application on a physical mobile device.
  2. Open the Proximity Sensor Demo.
  3. Select Check Availability.
  4. Verify that the sensor is available.
  5. Select Enable Sensor.
  6. Place your hand near the device's proximity sensor.
  7. Select Get Proximity State.
  8. Verify that the state changes to Near.
  9. Move your hand away.
  10. Select Get Proximity State again.
  11. Verify that the state changes to Far.
  12. Select Disable Sensor when finished.

17. Limitations

  • Requires a physical mobile device with a supported proximity sensor.
  • Cannot be fully tested using browser preview.
  • Proximity sensor availability depends on device hardware.
  • Sensor behavior can vary between Android and iOS devices.
  • Screen dimming or touch behavior is controlled by the device operating system.
  • The component currently provides proximity state detection and sensor control only.
  • The component does not provide a built-in automatic polling mechanism; applications that require continuous monitoring can implement their own Timer and call GetProximityState.

18. Troubleshooting

Proximity sensor is not available

Use:

CheckProximityAvailability

and verify that:

IsAvailable = True

Also verify that the application is running on a physical device that contains a proximity sensor.

GetProximityState does not return the expected value

Make sure the sensor has first been enabled:

EnableProximitySensor

Then call:

GetProximityState

Screen dims when testing

This can be expected behavior when the proximity sensor detects a nearby object. The behavior is controlled by the mobile operating system.

Changes to the plugin are not reflected in the installed application

Because this is a native mobile plugin, generate and install a new mobile build after making changes to the native plugin configuration. Native plugin changes require a new application package.


19. Quick Reference

ActionInputOutput
CheckProximityAvailabilityNoneIsAvailable
EnableProximitySensorNoneSuccess, ErrorMessage
DisableProximitySensorNoneSuccess, ErrorMessage
GetProximityStateNoneIsNear, Success, ErrorMessage

Proximity State

IsNearMeaning
TrueObject detected near sensor
FalseNo object detected near sensor

20. Third-Party Component

This component uses the Cordova Proximity Sensor Plugin as its underlying native plugin.

The underlying plugin is distributed under the Apache License 2.0. Its original license and attribution are retained in the plugin repository.