How to Determine if Android Device has Proximity Sensor Feature

public static final String FEATURE_SENSOR_PROXIMITY was added in API level 7
Feature for getSystemAvailableFeatures() and hasSystemFeature(String).
The device includes a proximity sensor.
Constant Value: "android.hardware.sensor.proximity"


1. Get a PackageManager Instance named myPackageManager.

2. Create a Boolean Variable named bolProximitySupported

3. Set the Minimum and Target SDK version  to or greater. 

4. In the onCreate method, add the below code. This will return the proximity sensor ability to a boolean named bolProximitySupported. It will then display a toast displaying the proximity sensor ability of the device to the user.

bolProximitySupported = myPackageManager.hasSystemFeature(PackageManager.FEATURE_SENSOR_PROXIMITY);
if (bolProximitySupported) {
Toast.makeText(this, "Device has Proximity Sensor capability", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "No Proximity Sensor capability!", Toast.LENGTH_LONG).show();
}

5. Compile and run!

Resources:
http://developer.android.com/reference/android/content/pm/PackageManager.html#FEATURE_SENSOR_PROXIMITY
http://developer.android.com/guide/topics/sensors/sensors_position.html