Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect when android device is in a moving car

Tags:

android

For a personal project, I'm trying to detect when an android device is with someone driving. I initially thought of using GPS to determine average velocity, but decided that would consume power and requires that the user has GPS enabled at all times. I'd heard that it's possible to tell when someone switches cell towers (on both android and iOS), but is there a broadcast intent for this? I'm very new to Android development, so was hoping I could register a broadcast receiver to run when I believe the device is in a moving car.

I'm not sure if I can create my own broadcast intents and I assume I couldn't rely on a background process to always be running since android may kill it if memory is needed.

As a side note, I notice that some apps, like skype, have a background process that restarts itself even if I force kill it. How do they do this? My thought would be to have a broadcast receiver for when device moves, turns on, etc. to restart the background process... is that what they do?

Thanks for any info!

like image 310
ravun Avatar asked Mar 17 '11 16:03

ravun


2 Answers

I think the following tutorials could help you a bit. I'm still not sure if it's possible to catch a Location Changed Update in a broadcast receiver. But you could also write your service (which usually will not be killed that likely than an usual app) which would poll the location information and check if a change had occurred.

  • Location-Based Services Using CellID in Android
  • Developing Proximity Alerts for Mobile Applications using the Android Platform

I hope this helps. Regards

like image 168
saxos Avatar answered Sep 23 '22 01:09

saxos


I would suggest GPS would give you much better indication of motion, since you likely change towers somewhat infrequently. Even mapping applications that are able to triangulate your position using tower signal are extremely inaccurate. Often even with a very good signal they aren't able to triangulate your position any better than within 1600m.

like image 1
Canuteson Avatar answered Oct 18 '22 00:10

Canuteson