npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@capawesome/capacitor-proximity-sensor

v0.1.2

Published

Capacitor plugin to read the device's proximity sensor on Android and iOS.

Readme

Capacitor Proximity Sensor Plugin

Capacitor plugin to read the device's proximity sensor.

Features

The Capacitor Proximity Sensor plugin is one of the most complete proximity sensing solutions for Capacitor apps. Here are some of the key features:

  • 🖥️ Cross-platform: Supports Android and iOS.
  • 📏 Proximity detection: Detect whether an object is close to the screen.
  • ⚡ Real-time updates: Continuous proximity data with event listeners.
  • 🤝 Compatibility: Works alongside the Accelerometer, Barometer and Gyroscope plugins.
  • 📦 CocoaPods & SPM: Supports CocoaPods and Swift Package Manager for iOS.
  • 🔁 Up-to-date: Always supports the latest Capacitor version.

Missing a feature? Just open an issue and we'll take a look!

Use Cases

The Proximity Sensor plugin is typically used to react when an object is close to the device's screen, for example:

  • Calling and VoIP apps: Detect when the user holds the device to their ear during a call.
  • Pocket detection: Detect when the device is in a pocket or bag to ignore accidental input.
  • Proximity-triggered actions: Start or stop app behavior based on real-time measurement events.

Compatibility

| Plugin Version | Capacitor Version | Status | | -------------- | ----------------- | -------------- | | 0.x.x | >=8.x.x | Active support |

Guides

Installation

You can use our AI-Assisted Setup to install the plugin. Add the Capawesome Skills to your AI tool using the following command:

npx skills add capawesome-team/skills --skill capacitor-plugins

Then use the following prompt:

 Use the `capacitor-plugins` skill from `capawesome-team/skills` to install the `@capawesome/capacitor-proximity-sensor` plugin in my project.

If you prefer Manual Setup, install the plugin by running the following commands and follow the platform-specific instructions below:

npm install @capawesome/capacitor-proximity-sensor
npx cap sync

Android

Proguard

If you are using Proguard, you need to add the following rules to your proguard-rules.pro file:

-keep class io.capawesome.capacitorjs.plugins.** { *; }

Configuration

No configuration required for this plugin.

Usage

The following examples show how to check whether the proximity sensor is available, get a single measurement, and start and stop continuous measurement updates.

Check whether the sensor is available

Not every device has a proximity sensor, so check its availability first. Only available on Android and iOS:

import { ProximitySensor } from '@capawesome/capacitor-proximity-sensor';

const isAvailable = async () => {
  const result = await ProximitySensor.isAvailable();
  return result.available;
};

Get a single measurement

Read the most recent measurement from the proximity sensor. Note that on iOS, reading the measurement enables proximity monitoring, which turns off the screen while an object is close to the sensor (see Screen Dimming (iOS)):

import { ProximitySensor } from '@capawesome/capacitor-proximity-sensor';

const getMeasurement = async () => {
  const measurement = await ProximitySensor.getMeasurement();
  console.log('Near: ', measurement.near);
  console.log('Distance: ', measurement.distance);
};

Start and stop measurement updates

Listen for continuous measurement events. On iOS, proximity monitoring stays enabled until stopMeasurementUpdates() (or removeAllListeners()) is called:

import { ProximitySensor } from '@capawesome/capacitor-proximity-sensor';

const startMeasurementUpdates = async () => {
  await ProximitySensor.addListener('measurement', measurement => {
    console.log('Near: ', measurement.near);
    console.log('Distance: ', measurement.distance);
  });
  await ProximitySensor.startMeasurementUpdates();
};

const stopMeasurementUpdates = async () => {
  await ProximitySensor.stopMeasurementUpdates();
};

const removeAllListeners = async () => {
  await ProximitySensor.removeAllListeners();
};

API

getMeasurement()

getMeasurement() => Promise<GetMeasurementResult>

Get the latest measurement.

This method returns the most recent measurement from the proximity sensor.

On iOS, reading the measurement enables proximity monitoring, which turns off the screen while an object is close to the sensor.

Only available on Android and iOS.

Returns: Promise<Measurement>

Since: 0.1.0


isAvailable()

isAvailable() => Promise<IsAvailableResult>

Check if the proximity sensor is available on the device.

Only available on Android and iOS.

Returns: Promise<IsAvailableResult>

Since: 0.1.0


startMeasurementUpdates()

startMeasurementUpdates() => Promise<void>

Start emitting measurement events.

On iOS, this enables proximity monitoring, which turns off the screen while an object is close to the sensor.

Only available on Android and iOS.

Since: 0.1.0


stopMeasurementUpdates()

stopMeasurementUpdates() => Promise<void>

Stop emitting measurement events.

On iOS, this disables proximity monitoring.

Only available on Android and iOS.

Since: 0.1.0


addListener('measurement', ...)

addListener(eventName: 'measurement', listenerFunc: (event: MeasurementEvent) => void) => Promise<PluginListenerHandle>

Called when a new measurement is available.

Only available on Android and iOS.

| Param | Type | | ------------------ | ----------------------------------------------------------------------- | | eventName | 'measurement' | | listenerFunc | (event: Measurement) => void |

Returns: Promise<PluginListenerHandle>

Since: 0.1.0


removeAllListeners()

removeAllListeners() => Promise<void>

Remove all listeners for this plugin.

Since: 0.1.0


Interfaces

Measurement

| Prop | Type | Description | Since | | -------------- | --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----- | | distance | number | null | The distance between the sensor and the nearby object in centimeters (cm). Most devices only report whether an object is near or far, so this value is typically either 0 (near) or the sensor's maximum range (far). Only available on Android. Always null on iOS. | 0.1.0 | | near | boolean | Whether an object is close to the sensor. | 0.1.0 |

IsAvailableResult

| Prop | Type | Description | Since | | --------------- | -------------------- | -------------------------------------------------------- | ----- | | available | boolean | Whether the proximity sensor is available on the device. | 0.1.0 |

PluginListenerHandle

| Prop | Type | | ------------ | ----------------------------------------- | | remove | () => Promise<void> |

Type Aliases

GetMeasurementResult

Measurement

MeasurementEvent

Measurement

Screen Dimming (iOS)

On iOS, reading the proximity sensor requires enabling proximity monitoring via UIDevice. While monitoring is enabled, iOS automatically turns off the screen whenever an object (such as the user's ear or a hand) is close to the sensor, exactly like during a phone call. This is a system-level behavior that cannot be disabled.

For this reason, monitoring is only enabled while it is needed:

  • getMeasurement() enables monitoring, reads the current state and disables it again.
  • startMeasurementUpdates() keeps monitoring enabled until stopMeasurementUpdates() (or removeAllListeners()) is called.

Only call startMeasurementUpdates() when you actually want this behavior.

On Android, reading the proximity sensor has no effect on the screen.

FAQ

How is this plugin different from other similar plugins?

It covers the whole proximity story through one fully typed API: a one-time reading, continuous real-time measurement events, and an availability check, working consistently across Android and iOS. It surfaces platform specifics honestly — a distance in centimeters on Android and the near/far state on iOS — and documents the iOS screen-dimming behavior so there are no surprises. The package is kept current with the latest Capacitor version and ships for both CocoaPods and Swift Package Manager.

Why does the screen turn off on iOS when reading the sensor?

On iOS, reading the proximity sensor requires enabling proximity monitoring via UIDevice. While monitoring is enabled, iOS automatically turns off the screen whenever an object is close to the sensor, exactly like during a phone call. This is a system-level behavior that cannot be disabled. See the Screen Dimming (iOS) section for details.

Why is the distance value always null on iOS?

iOS only reports whether an object is near the sensor via the near property. The distance value in centimeters is only available on Android and is always null on iOS.

Why is the distance value always either 0 or the maximum range on Android?

Most devices only report whether an object is near or far instead of an exact distance. The distance value is therefore typically either 0 (near) or the sensor's maximum range (far).

How can I check whether a device has a proximity sensor?

Call the isAvailable() method before using the sensor. It returns whether the proximity sensor is available on the device.

Does this plugin work on the Web?

No, this plugin is only available on Android and iOS, since browsers do not expose the device's proximity sensor.

Can I use this plugin with Ionic, React, Vue or Angular?

Yes, the plugin is framework-agnostic. It works in any Capacitor app regardless of the web framework, including Ionic with Angular, React, or Vue, as well as plain JavaScript projects.

Related Plugins

  • Accelerometer: Capture the acceleration force along the x, y, and z axes.
  • Barometer: Obtain the static air pressure in hectopascals (hPa).
  • Gyroscope: Read the device's gyroscope sensor.
  • Light Sensor: Read the device's ambient light sensor.

Newsletter

Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our Capawesome Newsletter.

Changelog

See CHANGELOG.md.

License

See LICENSE.