You can check the presence of a compass sensor using hasSystemFeature() method.
SensorManager or Sensor both classes are designed for direct access and acquisition of raw sensor data. When it comes to assessing a system’s abilities, the PackageManager class can be used to recover information on application packages available on a given device.
PackageManager myCompass = getPackageManger();
If (!myCompass.hasSystemFeature(PackageManager.FEATURE_SENSOR_COMPASS)) {
// This device lacks a compass, disable the compass feature
}
Regards,
Nitesh Bavishiya