我正在开发一个使用传感器的 android 应用程序,我想知道检测设备是否具有特定传感器的最佳方法,比如接近传感器。
此外,是否有任何“过滤器”可以应用于清单,这样设备上没有接近传感器的用户将无法安装该应用程序?如果存在,此“过滤器”是否在 Google Play 上也有效,因此用户将无法看到该应用?
我正在开发一个使用传感器的 android 应用程序,我想知道检测设备是否具有特定传感器的最佳方法,比如接近传感器。
此外,是否有任何“过滤器”可以应用于清单,这样设备上没有接近传感器的用户将无法安装该应用程序?如果存在,此“过滤器”是否在 Google Play 上也有效,因此用户将无法看到该应用?
这很可能是您在以编程方式检查功能时正在寻找的内容
PackageManager PM= this.getPackageManager();
boolean gps = PM.hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS);
boolean acc = PM.hasSystemFeature(PackageManager.FEATURE_SENSOR_ACCELEROMETER);
此链接说明了您可以采取哪些措施来过滤市场中的应用程序,具体请查看该部分
检查特定传感器:
public String getSystemInfo(PackageManager pm/* activity.getPackageManager() */) {
return ""
+ "\nSDK: " + Build.VERSION.SDK_INT
+ "\nMODEL: " + Build.MODEL
+ "\nBrand: " + Build.BRAND
+ "\nManufacture: " + Build.MANUFACTURER
+ "\nAndroid Version: " + Build.VERSION.RELEASE
+ "\nSen-Fingerprint: " + hasFP()
+ "\nSen-Light: " + hasSen(pm, PackageManager.FEATURE_SENSOR_LIGHT)
+ "\nSen-Compass: " + hasSen(pm, PackageManager.FEATURE_SENSOR_COMPASS)
+ "\nSen-Proximity: " + hasSen(pm, PackageManager.FEATURE_SENSOR_PROXIMITY)
+ "\nSen-ECG(API 21): " + hasSen(pm, PackageManager.FEATURE_SENSOR_HEART_RATE_ECG)
+ "\nSen-Temp(API 21): " + hasSen(pm, PackageManager.FEATURE_SENSOR_AMBIENT_TEMPERATURE)
+ "\nSen-Accelerometer: " + hasSen(pm, PackageManager.FEATURE_SENSOR_ACCELEROMETER)
+ "\nSen-Humidity(API 21): " + hasSen(pm, PackageManager.FEATURE_SENSOR_RELATIVE_HUMIDITY)
+ "\nSen-Gyroscope(API 9): " + hasSen(pm, PackageManager.FEATURE_SENSOR_GYROSCOPE)
+ "\nSen-Barometer(API 9): " + hasSen(pm, PackageManager.FEATURE_SENSOR_BAROMETER)
+ "\nSen-HeartRate(API 20): " + hasSen(pm, PackageManager.FEATURE_SENSOR_HEART_RATE)
+ "\nSen-StepCounter(API 19): " + hasSen(pm, PackageManager.FEATURE_SENSOR_STEP_COUNTER)
+ "\nSen-StepDetector(API 19): " + hasSen(pm, PackageManager.FEATURE_SENSOR_STEP_DETECTOR);
}
public boolean hasFP() {
return (Build.FINGERPRINT != null && !Build.FINGERPRINT.equals(""));
}
public boolean hasSen(PackageManager packageManager, String sensor) {
try {
return packageManager.hasSystemFeature(sensor);
} catch (Exception ignored) {
return false;
}
}