Search code examples
androidaccelerometer

How to obtain and interpret information about movement from accelerometer


I'm writing Android application that sends the information about detected RSSI to the server. I want to attach also the information if the mobile user is moving. I have used the some pedometer app code to detect made steps.

Now I want to have boolean variable 'isMoving' that changes to true if step was detected, remains true for some time and is changed to false if the another step wasn't detected within this given period of time.

The isMoving value would be attached to the RSSI reports and sent if the report would be ready. (The reports are being generated independently and sent if the phone receives info about all available accesspoint's RSSIs).

I've tried using sleep() for movement detection, however always the sent 'isMoving' value was false even though the phone was moving while sending the report.

Step detector works fine (it buzzes, when step was made).

What other approach should I use to accomplish it?


Solution

  • I have solved problem. Figured out to do time stamp when step was detected:timeStamp = new Date().getTime() and then checked in the thread loop if(Date().getTime() - timeStamp > 1000). Turned out to be working just as I needed.