How to check if a specific sensor exists on the device?

I am developing an Android application that uses sensors, and I would like to know how best to determine if the device has a specific sensor, say, a proximity sensor.

Also, is there any “filter” that can be applied to the manifest, so users who don’t have a proximity sensor on their device will not be able to install the application ? If there is, this "filter" will also be valid on Google Play, so users will not be able to see the application ? I am new to Android development, any help is greatly appreciated. Thanks everyone!

+3
source share
1 answer

This is most likely what you are looking for when checking features programmatically

PackageManager PM= this.getPackageManager();
boolean gps = PM.hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS);
boolean acc = PM.hasSystemFeature(PackageManager.FEATURE_SENSOR_ACCELEROMETER);

This link explains what you can do to filter your application on the market, look specifically at the section

Market filters

+15
source

All Articles