Search code examples
androidandroid-activityandroid-hardwaregoogle-nownexus-5

Tapping into a phone's sensors to detect movement and stoppage


I'm a beginner with Android development. I noticed that my Nexus 5 can detected when I'm moving and when I'm stopped. I want to build an app that detects when I'm moving but when I've stopped and walked a few feet away from where I stopped, I want it to send a notification.

I know the sensors detect that I'm driving with a few seconds but I don't know if it detects that driving has stopped as quickly. I know that android has motion sensors APIs but I don't know which sensor to use and what sensor type is best for this type of movement detection.

I also know I would have to use GPS Permissions or whatever but I was wondering if anyone knew more about how I can approach this. "Approach" is not the best word since it makes it look like I'm trying to get people to help me solve this problem but I don't know how to word it.

Any help is appreciated.


Solution

  • The API you want is the google play services activity detection http://developer.android.com/training/location/activity-recognition.html. It doesn't use GPS (or at least not just), it uses the accelerometer mainly to detect speeding up and slowing down.

    As an aside, I one did this with just location data (network, not GPS for battery). Its harder than you think because of things like stopping for red lights, slowing for various reasons, etc. Don't expect perfection even from Google's stuff- it's a best guess.