0

I want to know if my android phone has been moved at all in the last 20 minutes.

I was thinking of using the step counter, but my phone doesn't have one (only on high end models it seems), so I'm out of luck there.

I was also thinking about using the gyro, but when the screen is off, then so to goes the gyro (or so I've read.. I would love to be wrong)

I'm thinking of using the cameras, or something else.

Anyone know of a way to figure out if the user has moved their phone. Or better yet walked with it in the last N minutes?

Super cool if there is an answer here. I was sort of thinking of bluetooth and IOT tracking, but that seems like a bazooka for a fly kind of thing.

Thanks

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
baash05
  • 4,394
  • 11
  • 59
  • 97
  • You might be able to keep sensors running using wakelock maybe – Jemshit Mar 24 '18 at 11:31
  • Yeah.. the problem I have with that, is I plan on leaving the app running all day. That would kill the battery. I might be able to turn the system on every minute and check gyro – baash05 Mar 24 '18 at 11:42
  • instead of listening all time you may use JobScheduler (which will trigger your method of detecting..) – Jemshit Mar 24 '18 at 11:44
  • How to detect movement of an android device? – krishank Tripathi Mar 24 '18 at 12:07
  • check this out for scenarion of user moving or not https://stackoverflow.com/a/49282110/9287163 – krishank Tripathi Mar 24 '18 at 12:09
  • want to fetch the movement in which users move the phone check this out https://stackoverflow.com/questions/48841066/fetching-direction-from-accelerometer-using-shake-action – krishank Tripathi Mar 24 '18 at 12:10
  • Yeah both those links don't work when the screen is off :( Gave SM a go before I posted. :) All good, I'll figure it out. JobScheduler might be a good lead. – baash05 Mar 24 '18 at 12:46

1 Answers1

2

You could use the Activity Recognition API for this. The Activity Recognition API detects how the user is using the device. It allows you to listen to certain activity changes. You could get notified when the user starts or stops a certain activity such as walking, driving, or when the device is still. You would have to add some custom logic to check if the device has moved within the last 20 minutes using these activity changes.

There is some delay in the API because the sensors are checked periodically. For our use-case, detecting if the user in a vehicle, we had delays off approximately 15-20 seconds.

Rockney
  • 10,380
  • 2
  • 20
  • 26