Android: where do PackageManager and SensorManager get their information?

落花浮王杯 提交于 2019-12-13 04:43:33

问题


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?


回答1:


Android is a stack of software and firmwares, which include Operating system, inbuilt applications and System services.

We can write our own services to provide some data to our applications. Like wise, we can use system services which provide some data to us. Thats why there is a call SensorManager sensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);



来源:https://stackoverflow.com/questions/19573624/android-where-do-packagemanager-and-sensormanager-get-their-information

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!