Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete an SMS from the inbox in Android programmatically?

Tags:

android

sms

On Android phones SMS messages registered to applications also get sent to the device's inbox. However to prevent clutter, it'd be nice to be able to remove application specific SMS messages from the inbox to reduce the potential overflow of those messages.

Questions on other Google groups on getting a definitive answer on a programmatic way to delete SMS messages from the Android inbox don't seem to be pressing.

So the scenario:

  • Android App startup.
  • register SMS message types X,Y and Z
  • messages P,Q,X,Y,Z stream in over the course of time, all deposited in inbox
  • Android application detects receipt of X,Y,Z (presumably as part of the program interrupt event)
  • process X,Y,Z
  • Desirement!!! X,Y,Z are deleted from the Android inbox

Has it been done? Can it be done?

like image 403
dmyung Avatar asked Jan 07 '09 04:01

dmyung


People also ask

How do you delete SMS messages on Android?

Delete individual text messagesTap the conversation. Touch and hold the message you want to delete. Optional: To delete multiple messages, touch and hold the first message, then tap more messages. Tap Delete to confirm.

How do you clean up messages on android?

To delete multiple messages, open the Textra SMS app on your phone and make sure it's set as default. Inside the app, tap and hold on any message you want to delete. When the message gets selected, a green will appear on its left side. To select more messages to delete, tap on them.

Why can't I delete my SMS messages?

Go to Settings, Apps, Apps Manager (or All), find you SMS app. Do a force stop, clear cache and clear data. Exit settings and reboot. that may help.


1 Answers

"As of Android 1.6, incoming SMS message broadcasts (android.provider.Telephony.SMS_RECEIVED) are delivered as an "ordered broadcast" — meaning that you can tell the system which components should receive the broadcast first."

This means that you can intercept incoming message and abort broadcasting of it further on.

In your AndroidManifest.xml file, make sure to have priority set to highest:

<receiver android:name=".receiver.SMSReceiver" android:enabled="true">     <intent-filter android:priority="1000">         <action android:name="android.provider.Telephony.SMS_RECEIVED" />     </intent-filter> </receiver> 

In your BroadcastReceiver, in onReceive() method, before performing anything with your message, simply call abortBroadcast();

EDIT: As of KitKat, this doesn't work anymore apparently.

EDIT2: More info on how to do it on KitKat here:

Delete SMS from android on 4.4.4 (Affected rows = 0(Zero), after deleted)

like image 168
Viktor Avatar answered Sep 21 '22 07:09

Viktor