Domanda

I have software designed for 2.3.3 where I am using the gravity sensor.

Code below -

private SensorManager sman = (SensorManager) getContext().getSystemService(Context.SENSOR_SERVICE);
private Sensor magnetfield, gravity;
...
magnetfield = sman.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
gravity = sman.getDefaultSensor(Sensor.TYPE_GRAVITY);

I decided to add support for version 2.1. However it seems TYPE_GRAVITY is not supported in 2.1, and I get an error that Sensor.TYPE_GRAVITY is not recognized anymore.

Questions - A) When I search for "Android gravity sensor 2.1" googles links to videos that demo gravity sensor in 2.1 devices. Does that mean there is a way to get access to it? B) If not, what is the lowest version that can use this? Couldn't find it in the SDK.

Thanks

È stato utile?

Soluzione

By looking at the source code you can see that the gravity sensor is actually computed using a Butterworth filter. I also asked a question on dsp (here). Hope the link helps because it helped me understand quite a lot of things.

For gravity sensor in versions < 2.3 you need to implement that filter yourself if you want the same results.

Here is the source code.

Later edit: Added a valid link!

Altri suggerimenti

Sensor TYPE_LINEAR_ACCELERATION and TYPE_GRAVITY are available since API Level 9 (Android 2.3), so you are not going to be able to use them on 2.1.

If you'd want implement it, I guess you should play with the orientation of the cellphone, so you could know How it is oriented, and accordingly the components of gravity in the acceleration.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top