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.