When GPS is not available how to get notified when the phone is in motion?

别说谁变了你拦得住时间么 提交于 2019-12-01 11:48:19

you can use a combination of the accelerometer and the digital compass, in phones that have them, to determine a speed and direction.

If all you need to do is determine if the person is walking, all you need is the accelerometer. Just process its output for foot steps.

There are plenty of tutorials on the web for detecting foot steps with an accelerometer.

You can also get your location from Wifi-Networks and Cell Towers. All location providers in Android are subclasses of android.location.LocationProvider. That's probably a good place to start. I don't know that either of those would be best for you, as their "range" can be several hundreds of feet wide.

Android accelerometer provides us the feature to know the acceleration using SensorEvent class. So use the object of the class, and handle onSensorChanged(), to determine the movement in the device.

x = sensorEvent.values[0]; States the acceleration in x direction.

So what you may be interested in is, find acceleration in x,y and z directions, and try to calculate the Average and standard deviation for the last 10 such samples. Working on the standard deviation will surely get you to the right point! If it goes to 0, it means device is still. If SD>0.5 for more than 15sec's or so..it means device is continously moving! Lemme know if you need more help!

Cheers, Nithin

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!