0

I am developing an application based on GPS / Accelerometer / Gyroscope and Linear Acceleration. I wanted to know, is there any way I can find out the hardware (Accelerometer / Gyroscope and Linear Acceleration) availability on my device. Because, as from given forums there are API's available to check whether the sensors are available but not given anything related to the hardware availability in the device.Thanks in advance

kaiz.net
  • 1,984
  • 3
  • 23
  • 31
Shweta
  • 807
  • 3
  • 11
  • 24
  • do you want to check gps availibity ? – Chirag Sep 17 '12 at 05:26
  • @ChiragRaval : I want to check the hardware availability for Accelerometer /Gyroscope and Linear Acceleration – Shweta Sep 17 '12 at 05:27
  • @ChiragRaval : thanx for your reply..I worked on your suggestion and referred http://www.anddev.org/accessing_the_accelerometer-t499.html. However, I am getting a same error "Sensors cannot be resolved to a variable"...Do I need to import anything else or make any other declaration in my manifest.xml file – Shweta Sep 17 '12 at 05:49

1 Answers1

4

Check GPS Availability on Android Device.

PackageManager pm = context.getPackageManager();
boolean hasGps = pm.hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS);

/* Check once here in the constructor if an * Accelerometer is available on this device. */

/** True when the Accelerometer-functionality is basically available. */

boolean accelerometerAvailable = false;

for (String aSensor : Sensors.getSupportedSensors())
     if (aSensor.equals(Sensors.SENSOR_ACCELEROMETER))
         accelerometerAvailable = true;

      if (!accelerometerAvailable)
           throw new UnsupportedOperationException("Accelerometer is not available.");

Check this link for Accelerometer is available on this device or not.

Chirag
  • 56,621
  • 29
  • 151
  • 198