Tag Archives: android

Location tracking

A few of you might know that I spend a lot of time helping on stackoverflow.com. One of the most ironic and frustrating things is when stackoverflow itself is the source of bad information. Sometimes bad code that mostly works gets voted up, and its impossible to fix it. So here’s my attempt to take one of those and do it right, in the hope I can help future newbies.

A common question asked is how to track your location via GPS. It’s a moderately complex API with a few corner cases that can trip up a beginner. So of course everyone wants to simplify it. Here’s the most common abstraction I see used- GPSTracker. Continue reading

Is the phone ringing?

About 2 years ago I was writing an app that needed to know when a call was happening.  More specifically, I needed to be able to detect when a call ended, its duration, and who it was made to.  The app was never released but it was a small app to categorize my calls so I could account for them and accurately charge for my consulting work (also so I could accurately deduct my business ratio of calls from my taxes).

This ended up being surprisingly annoying on Android.  Android’s method of sending events to activities that aren’t running (BroadcastReceivers) aren’t too bad, but they aren’t always convenient to work with.  Instead of getting specific functions called on an object somewhere, you get generic calls on an object with no context and no saved state.  In addition, Android doesn’t have call starting and call end broadcasts.  It has an outgoing call started broadcast, but call ends can only be detected by checking the ringing state changing and duration has to be calculated on your own.  Detection of outgoing calls needs to be detected in a similar way.

I’m ok with writing code like this once.  I pretty much have no choice.  But I’m not going to do it twice.  There’s better ways.

Continue reading