Deleting Android SMS programmatically

Actually, the code in my post is 100% correct. The problem was that Android needs some time to store the SMS upon receiving it. So the solution is to just add a handler and delay the delete request for 1 or 2 seconds.

This actually solved the whole issue.

EDIT (thanks to Maksim Dmitriev):

Please consider that you can’t delete SMS messages on devices with Android 4.4.

Also, the system now allows only the default app to write message data to the provider, although other apps can read at any time.

http://developer.android.com/about/versions/kitkat.html

No exception will be thrown if you try; nothing will be deleted. I have just tested it on two emulators.

How to send SMS messages programmatically

Leave a Comment