Search code examples
javaandroidandroid-manifestandroid-sensorsgoogle-play

How check if a specific sensor exists on a device?


I'm developing an android app that uses Sensors and I would like to know the best way to detect if a device has a specific sensor, let's 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 won't be able to install the app? If exists, will this "filter" also be valid on Google Play, so users won't be able to see the app?


Solution

  • This is most likely what you are looking for in checking the features programtically

    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 in the marketplace, look specifically at the section

    Market Filters