Jyosna
Jyosna

Reputation: 4446

Android how to work with sensor?

I want when I shake my phone it randomly generate some no. I am working with API2.2 and try to using SensorListener but it shows that it is deprecated. so which one I have to use.

please give me any suggestion how to do this. Thank you

Upvotes: 0

Views: 868

Answers (3)

Milos Cuculovic
Milos Cuculovic

Reputation: 20223

Here is an exemple of how to use the sensor manager class on android:

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

Upvotes: 0

areyling
areyling

Reputation: 2191

As Xion said, use SensorEventListener. There are many examples of this here on SO; for instance, check out this one. For testing shakes in an emulator, something like SensorSimulator might also help.

Upvotes: 0

Xion
Xion

Reputation: 22770

Use SensorEventListener instead. There is quite good explanation of it in the docs. Accelorometer is probably the sensor you want to use here.

Upvotes: 1

Related Questions