2010-03-03

Send SMS programmatically

I am developing a feature that sends SMS automatically. SmsManager can be used to send SMS message programmatically in Android 1.5 and above. But, when I open built-in Messages application, I found that the SMS I sent programmatically is not at the conversation threads.


I was told that public SMS content provider API android.provider.Telephony was taken off SDK since 1.0. It's too bad we can't just reuse it. Fortunately, Android is an open-source platform and we can look into source code to see how messages are inserted in conversation threads.

The SMS/MMS in Android are stored in SQLite database and we can use SQLite database browser to see if any thing goes wrong. Two database tables need our attention, sms and threads. If the thread_id of an SMS record has a value less than 1, it will not be grouped in the conversation.

 


By this observation, when a SMS recorded is inserted into database, the thread_id must be queried by recipient in order for it to be successfully grouped into conversations.

You can take a look at android.provider.Telephony.java to understand what I say.
(static class Sent and Threads)