Working with SMS in Android


I'm actually interested in how to work with SMS in Android.

Specifically :

  1. Sending a message. When sending a message, is it programmatically recorded in the database?
  2. How to remove SMS from the table?
  3. How to edit SMS in the database?

PS It is not worth talking about the manifesto, the permitions. Specifically, I'm interested in the questions above.


1) Programmatically sending a message (not via an Intent ) is easy. It's easy to google – I won't even give a link. When sending to the database, it is not written – you need to do something like this yourself:

ContentValues values = new ContentValues();
values.put("address", "123456789");
values.put("body", "foo bar");
getContentResolver().insert(Uri.parse("content://sms/sent"), values);

2) Removing SMS from the database is also quite simple:

 activity.getContentResolver().delete(Uri.parse("content://sms/" + id), null, null); //id - идентификатор сообщения

3) Editing is identical. You need to get a list of SMS, then pull out the desired one by id, then write it back.

You need to keep a couple of permissions in the manifest:

<uses-permission android:name="android.permission.READ_SMS"/>
<uses-permission android:name="android.permission.WRITE_SMS"/>

The hardest part is intercepting incoming messages – there are many undocumented features. Only KitKat has official support for intercepting incoming messages.

Scroll to Top