I have been asked this question in an interview, someone please guide me.
Which of the code is the correct way to check if a Compass sensor is present on the system? Explain your answer.
Answer A:
PackageManager m = getPackageManager();
if (!m.hasSystemFeature(PackageManager.FEATURE_SENSOR_COMPASS)) {
// This device does not have a compass, turn off the compass feature
}
Answer B:
SensorManager m = getSensorManager();
if (!m.hasSystemFeature(SensorManager.FEATURE_SENSOR_COMPASS)) {
// This device does not have a compass, turn off the compass feature
}
Answer C:
Sensor s = getSensor();
if (!s.hasSystemFeature(Sensor.FEATURE_SENSOR_COMPASS)) {
// This device does not have a compass, turn off the compass feature
}