问题
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