如何检查设备上是否存在特定传感器?

Ped*_*ito 3 java android android-manifest android-sensors google-play

我正在开发一个使用传感器的Android应用程序,我想知道检测设备是否有特定传感器的最佳方法,比如接近传感器.

此外,是否有任何"过滤器"可以应用于清单,因此在其设备上没有接近传感器的用户将无法安装该应用程序?如果存在,此"过滤器"在Google Play上也会有效,因此用户将无法看到该应用吗?我是android开发的新手,非常欢迎任何帮助.谢谢你们!

Idi*_*tic 16

这很可能是您在编程检查功能时所寻求的

PackageManager PM= this.getPackageManager();
boolean gps = PM.hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS);
boolean acc = PM.hasSystemFeature(PackageManager.FEATURE_SENSOR_ACCELEROMETER);
Run Code Online (Sandbox Code Playgroud)

此链接说明了如何在市场中过滤应用程序,具体查看该部分

市场过滤器