1

I am working in a project, it doesn't work and I suppose that the error is here: should I write something in manifest.xml when I want to work with sensors : compass, gyroscope and accelerometer?

Thanks

RiadSaadi
  • 391
  • 2
  • 7
  • 16

3 Answers3

6
<uses-feature android:name="android.hardware.sensor.accelerometer" android:required="true" />

you have to declare this in manifest.xml

Mukesh Kumar Singh
  • 4,512
  • 2
  • 22
  • 30
  • 1
    Sorry but it is not an obligation. – RiadSaadi Dec 11 '13 at 13:29
  • 1
    This is not required to use the sensor. This is a Google Play filter that will restrict the app from devices that do not have an accelerometer. This is documented at https://developer.android.com/guide/topics/sensors/sensors_overview.html – Chris Miller Jan 31 '18 at 18:26
4

Provide permissions in manifest.

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

And also check below work:

sensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_NORMAL);
sensorManager.registerListener(this, magnetometer, SensorManager.SENSOR_DELAY_NORMAL);

Do not forget to unregister them.

More: http://developer.android.com/reference/android/hardware/SensorManager.html

Note: Android SDK folder also contains some helpful sensor sample applications

mark True or voteup if helpful...

Hamad
  • 5,096
  • 13
  • 37
  • 65
Macrosoft-Dev
  • 2,195
  • 1
  • 12
  • 15
  • 4
    you could just simply give a reference of this.http://stackoverflow.com/questions/8970065/cant-access-the-sensors-in-android. It was not needed to copy and paste. – Mukesh Kumar Singh Dec 10 '13 at 14:51
0

Manifest is the class where you can only write what application contains: application version, activitites, permissions etc. What type of data you want to entering. If you want to enter string. so place it in strings.xml.

Barry Michael Doyle
  • 9,333
  • 30
  • 83
  • 143
Macrosoft-Dev
  • 2,195
  • 1
  • 12
  • 15