Question

I'm writing an android app that has a standard activity, but also needs to monitor incoming/outgoing calls and texts at all times. In addition, the app needs to notify users of information once a day without having the activity open. The information it notifies users of is stored in a database, so communication with the activity is not necessary. I've been researching for a week and still can't decide how to go about doing this. My instinct tells me I need a remote service that has a constantly running broadcast receiver, but every remote service example I see is overly complicated. Could anyone help me better understand what steps I need to take? Thanks in advance.

Was it helpful?

Solution

My instinct tells me I need a remote service that has a constantly running broadcast receiver

Um, no. I say that, because:

  • There is only one application, and so there is no need for a "remote" service
  • A "service that has a constantly running broadcast receiver" is a really bad idea, as users will attack you with task killers and, even if they don't, Android will terminate your service eventually anyway as being a waste of space

Use BroadcastReceivers registered in your manifest for broadcasts that can occur at any time, as they will get control even if nothing else of your application is running. Use an IntentService for doing any "heavy lifting" that is needed by those BroadcastReceivers, as BroadcastReceiver get control (in onReceive()) on the main application thread and therefore should do as little work as possible. Also, use AlarmManager to signal a BroadcastReceiver (or, possibly, your IntentService) to raise a Notification for your once-daily event.

Also, please be advised that there is no way for you to "monitor...outgoing...texts", and that to "monitor...incoming...texts" requires you to use an undocumented capability of Android. While probably android.provider.Telephony will not be going away, you just need to be aware of the risk involved.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top