Tonight I started and almost finished the framework for my first Android app.
1. Edit my manifest to give me permissions to receive and read SMS.
2. Edit my manifest to point to a receiver class for SMS events.
3. Create a main class to stop and start the background Reader service.
4. I create a TextReceiver BroadcastListener that listens for system SMS messages from the OS.
5. I start a Reader service that listens in the background for notifications (an Intent stuffed with Extras from my TextReceiver using startService(Intent))
When a new inbound message arrives in my TextReceiver class, I pass an intent to my TextReader class. (Android MAKES you do it this way. They say you can’t do any asynchronous stuff in your system event listener classes)
Right now all this does in the TextReader class is just pop up a Toast every time a txt message comes in (until you stop the service manually). This is great because it works no matter what other app you might be in.
It’s just a simple matter of checking “Are your headphones plugged in” and then instead of a toast message, invoking Android’s TTS function inside of TextReader. Other steps after that will be to pull the calling party name from inbound calls, as well as sender name and message content for XMPP messages.
I should have this app completed in a few more nights of hacking. Awesome.
I was able to piece this together with chunks from developer.android.com, as well as some Google searching. It’s just a matter of stringing together a bunch of other people’s samples to do what you want.