Android:PackageManager和SensorManager在哪里获取其信息? [英] Android: where do PackageManager and SensorManager get their information?

查看:216
本文介绍了Android:PackageManager和SensorManager在哪里获取其信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android上,要查找可用的系统功能,您可以执行以下操作:

PackageManager pm = getPackageManager();
for (FeatureInfo fi : pm.getSystemAvailableFeatures()) {
    String feature_name = fi.name;
    if(fi.name == null){
        feature_name = "GlEs Version " + fi.getGlEsVersion();
    }
    Log.i("theTag", feature_name + "");
}

类似地,要找出可用的传感器,您可以执行以下操作:

SensorManager sensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
List<Sensor> sensor_list = sensorManager.getSensorList(Sensor.TYPE_ALL);
for (Sensor s : sensor_list) {
    Log.i("theTag", s.getName() + " - type: " + s.getType());
}

我的问题是Android如何知道PackageManager和SensorManager应该报告什么?设备制造商提供了某种清单还是系统轮询了组件以查看可用的组件?发生冲突时,两者中哪一个更具权威性?

解决方案

设备上存在的所有传感器的列表由HAL报告 实施.

来自: https://source.android.com/devices/sensors

HAL(硬件抽象层)从驱动程序获取信息,而驱动程序则从传感器集线器获取信息.

在官方页面上了解有关Android Sensor堆栈的更多信息: https://source .android.com/devices/sensors/sensor-stack

On Android, to find out the available system features you can do something like:

PackageManager pm = getPackageManager();
for (FeatureInfo fi : pm.getSystemAvailableFeatures()) {
    String feature_name = fi.name;
    if(fi.name == null){
        feature_name = "GlEs Version " + fi.getGlEsVersion();
    }
    Log.i("theTag", feature_name + "");
}

Similarly, to find out the available sensors you can do something like:

SensorManager sensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
List<Sensor> sensor_list = sensorManager.getSensorList(Sensor.TYPE_ALL);
for (Sensor s : sensor_list) {
    Log.i("theTag", s.getName() + " - type: " + s.getType());
}

My question is how does Android know what the PackageManager and SensorManager should report? Do the device manufacturers provide some kind of manifest or does the system poll the components to see what is available? Which of the two is more authoritative in the event of a conflict?

解决方案

The list of all sensors present on the device is reported by the HAL implementation.

From: https://source.android.com/devices/sensors

The HAL (Hardware Abstraction Layer) gets its information from the drivers, which gets its info from the sensor hub.

Read more about the Android Sensor stack on the official page: https://source.android.com/devices/sensors/sensor-stack

这篇关于Android:PackageManager和SensorManager在哪里获取其信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆