Proximity Sensor in Mobile Apps

Use the proximity sensor to detect when something is near the screen — turn off the display during calls or put your app in pocket mode.

Timothy Lindblom

Founder, Newly

The proximity sensor is the small infrared LED + photodiode near your front-facing camera. It returns "near" or "far" — that's it. The original use case was turning off the screen when you hold the phone to your ear, but it's also useful for pocket-mode detection, hands-free interactions, and any UI that should react when an object covers the top of the device.

Key Takeaways

  • Most proximity sensors are binary (near / far). Some Android sensors expose distance in cm, but values above ~5 cm typically just clip to the maximum.
  • iOS exposes proximity through `UIDevice.current.proximityState` after enabling proximity monitoring.
  • Android uses `Sensor.TYPE_PROXIMITY` via SensorManager.
  • No runtime permission is needed on either platform.

Proximity Sensor at a Glance

Binary
Most sensors: near / far
~5 cm
Typical detection range
No
Permission required
~100%
Smartphone availability

What It Is & How It Works

What it is. A short-range infrared sensor next to the earpiece. It detects whether something is within a few centimetres of the front of the device. The OS uses it to blank the screen during calls so the user's cheek doesn't hang up.

How it works. You opt in to proximity events and receive a state change every time the sensor crosses its near/far threshold.

Units & signal. iOS: boolean `proximityState`. Android: float distance in cm (often only reports 0 or `maximumRange`).

What You Can Build With It

Auto-dim during a call

The OS does this for you in voice calls, but VoIP apps need to enable it manually.

Example: A walkie-talkie app blanks the screen when held to the user's ear.

Pocket / face-down mode

Detect when the device is in a pocket or face-down to suppress notifications or pause media.

Example: A music app that pauses when stuffed in a pocket.

Hands-free gestures

Wave a hand over the device to advance to the next slide / mute audio.

Example: A recipe app you can advance with a wave when your hands are floury.

Privacy auto-lock

Lock the app immediately when something covers the screen.

Example: A wallet app that locks if it senses a hand cupped over the screen.

Permissions & Setup

No runtime permission required on either platform.

iOS · Info.plist

No special permission keys required.

Android · AndroidManifest.xml

No special permission keys required.

Code Examples

Setup

  • Expo: install `expo-modules-core` and add a tiny native wrapper, or use a community module like `react-native-proximity`
  • iOS: enable `UIDevice.proximityMonitoringEnabled` and observe `UIDeviceProximityStateDidChangeNotification`
  • Android: register a listener for `Sensor.TYPE_PROXIMITY`
// Using react-native-proximity (community module)
import Proximity from 'react-native-proximity';
import { useEffect } from 'react';

export function useProximity(onChange: (near: boolean) => void) {
  useEffect(() => {
    const sub = Proximity.addListener(({ proximity }) => onChange(proximity));
    return () => sub.remove();
  }, [onChange]);
}

Tip: With Newly, you describe the feature you want and the AI agent wires up the sensor, permissions, and UI for you. Try it free.

Best Practices

  • Treat the value as binary

    Don't try to read distance from an Android proximity sensor — most return only 0 and `maximumRange`.

  • Disable when off-screen

    Stop monitoring when your activity / screen is no longer visible, to avoid surprise screen-off events.

  • Use the OS for actual phone calls

    Native phone and VoIP frameworks already handle proximity-based screen-off — you only need this manually for novel UIs.

  • Provide a tactile / sound cue

    When the screen blanks because of proximity, users can think the app froze. A subtle haptic when "near" engages helps.

Common Pitfalls

False positives in cases

Folio cases and screen protectors can trip the sensor permanently.

Mitigation: Allow the user to disable proximity-based behaviour from settings.

Different sensors on different devices

Some devices report distance, some only near/far, some have a wider detection range.

Mitigation: Always compare against `maximumRange` rather than hard-coding a 5 cm threshold.

Proximity overrides screen brightness on iOS

When proximity monitoring is enabled, iOS will dim the screen automatically — sometimes unexpectedly.

Mitigation: Disable monitoring as soon as you no longer need it.

When To Use It (And When Not To)

Good fit

  • VoIP / push-to-talk apps that mimic regular calls
  • Pocket and face-down detection
  • Hands-free wave gestures in cooking / driving / DIY apps
  • Auto-lock for privacy-sensitive apps

Look elsewhere if…

  • Reliable distance measurement — use depth or ultrasonic sensors
  • High-rate gesture recognition — the sensor only fires on state change
  • Detecting people in a room — the range is centimetres, not metres
  • Anything you want to work through a thick case

Frequently Asked Questions

Why does my screen sometimes stay black after a call?

Usually a stuck proximity sensor — dust on the front-facing window, or a screen protector covering it. Cleaning the area or removing the protector typically fixes it.

Can I read distance in centimetres?

On a few Android devices yes, but most just return 0 (near) or `maximumRange` (far). Treat it as a boolean.

Does proximity monitoring drain the battery?

Negligibly. The sensor is event-driven and very low-power. The screen blanking it triggers actually saves battery.

Why do I need this on iOS if the OS handles calls?

You don't for native CallKit calls. You do need it for custom voice UIs, walkie-talkie apps, sleep apps, AR experiences, etc.

Build with the Proximity Sensor on Newly

Ship a proximity sensor-powered feature this week

Newly turns a description like “use the proximity sensor to auto-dim during a call into a real React Native app — permissions, native modules and UI included. Full source code is yours, and you can publish to the App Store and Google Play directly from the dashboard.

Start Building Your App

Want a deeper dive on the underlying APIs? See Expo Sensors, Apple Core Motion and Android sensor framework.

Continue Learning