I am deleting an SMS from the inbox but I want to know: How can I delete it before it reaches the inbox?
-
2Is j2ee really a matching tag here? – jitter Nov 16 '09 at 11:42
-
1Why would java be incorrect don't you program in java on Android? – jitter Nov 16 '09 at 11:51
-
3This reeks of evil. You shouldn't be doing this. – MattC Nov 17 '09 at 03:14
-
1actually i am not going for any evil its only a optional to make customer relief from unwanted distrurbance – umakant Nov 24 '09 at 06:43
-
43There are legitimate uses! For example if you want to do something (send GPS location, wipe or something) on your phone via SMS in case it is stolen; you don't want whoever who stole the phone to see that SMS message. – polyglot Aug 04 '10 at 14:15
-
@polyglot: There may be legit uses, but there are evil full on fraudulent uses too--uses that steal money from people. **EVIL** (yes, caps *and* bold) – Stu Thompson Nov 17 '10 at 19:27
-
21Come on people! This is definitely NOT "evil" at all. @polyglot is right! I'm doing an application to confirm the user's number (as Viber do) and I need it. Everything can be used as "evil". Don't install evil apps, just that. – Felipe Oct 08 '11 at 00:11
5 Answers
Yes.
Despite some negative reactions to this question, there are legitimate uses for SMS interception. For example: automating phone number verification, services which are provisioned via SMS (though generally this should be done with data SMS), or for applications which otherwise improve the user experience by processing specially-formatted messages in order to show them in a nice Android-specific UI.
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.
If you define an android:priority
attribute on your SMS-listening <intent-filter>
, you will then receive the notification before the native SMS application.
At this point, you can cancel the broadcast, preventing it from being propagated to other apps.
Update (October 2013): When Android 4.4 arrives, it will make changes to the SMS APIs which may affect an app's ability to influence SMS delivery.
Check out this Android Developers blog post for some more info:
http://android-developers.blogspot.com/2013/10/getting-your-sms-apps-ready-for-kitkat.html

- 110,418
- 27
- 198
- 193
-
13Holy god. This is true! I have always assumed it would be the other way around! For proof, look [here](https://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=telephony/java/com/android/internal/telephony/SMSDispatcher.java;hb=HEAD#l420). Wow. Wish I could give you more than one upvote ;) – Hamy Aug 01 '10 at 16:59
-
1@kakopappa: Yes, as mentioned in the answer it works from Android 1.6+. – Christopher Orr Feb 07 '11 at 14:46
-
Thanks it works!! If you still receiving notifications, try restarting the phone. – oracleruiz Jan 11 '12 at 19:51
-
Hey, this also worked for me until I installed the Handscent SMS app on my SGS2, now I'm not able to retrieve SMS anymore as Handscent is catching them before... I tried to set `android:priority` to `0` `1` and even `999` (as this seems to be the last number accepted) but I couldn't figure it out - has anybody had the same problem and eventually a solution for it? – herom Apr 04 '12 at 12:48
-
1@herom I have apps which use priority `1000`, so it is possible. In fact, Handcent are using priority `2147483647`. – Christopher Orr Apr 04 '12 at 19:30
-
2This worked for me to :) My app catch message first and there is not notification but then sms is not getting to Messages inbox. Like it was never received, only in my app. Is there a way to use abort broadcast but to receive messages in inbox? – androidEnthusiast Sep 11 '12 at 21:19
-
7It's important to bear in mind the new API level 19 as @ChristopherOrr says in his update. There it says `"Beginning with Android 4.4—any attempt by your app to abort the SMS_RECEIVED_ACTION broadcast will be ignored so all apps interested have the chance to receive it."`. – GoRoS Jan 10 '14 at 07:53
-
Can you please see here http://stackoverflow.com/questions/25988574/delete-sms-from-android-on-4-4-4-affected-rows-0zero-after-deleted ? – Gangadhar Nimballi Sep 23 '14 at 07:46
-
Regarding the example of intercepting SMS for phone number verification, here's the proper way to do that: https://developers.google.com/identity/sms-retriever/request – Daniel Oct 24 '17 at 19:05
Step-1: Create your custom broadcast receiver to receive sms. write the logic to abort the broadst so that the message will not be available to your inbox
public class SMSReceiver extends BroadcastReceiver
{
public void onReceive(Context context, Intent intent)
{
if(conditionMatches){
abortBroadcast();
}
}
}
Step-2 Register broadcast receiver in AndoridManifest and put android:priority value a large number
<receiver android:name=".SMSReceiver" >
<intent-filter android:priority="1000">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
Thats It
How does the above code work
As SMS receiving broad cast is an ordered broadcast the receiver with high priority will receive first so your application receive first and after receiving you are aborting broadcast. So no other application can receive it. Hence the sms will not exist in inbox

- 53,011
- 55
- 178
- 243
-
can we have a broadcast receiver ,when the user presses message inbox,so that i can develop a lock screen .. – Vamsi Pavan Mahesh Feb 15 '14 at 08:12
The below("android:priority" and abortBroadcast()) solution works as long as Android Messaging application as default(I meant stock Android Messaging application). If user installs "GoSMSPro" or "HandcentSMS", these applications still show messages in inbox, I believe this due to "android:priority". I don't see any better way to fix the above issue, if third party messaging applications installed on the phone.

- 91
- 1
- 1
-
2Good point. But this should be a comment, not an answer. Is it possible to move it? --- and what if you put a very high value? As android:priority="9999" ? for example? Have you tried that? – Felipe Oct 08 '11 at 00:14
-
4@FelipeMicaroniLalli actually GO SMS PRO, etc... use 2147483647 for their priority – rf43 Nov 03 '11 at 18:16
-
1
-
3It is the largest unsigned integer http://en.wikipedia.org/wiki/Integer_(computer_science) the max that Android supports is 999. http://developer.android.com/reference/android/content/IntentFilter.html#SYSTEM_HIGH_PRIORITY – rf43 Nov 08 '11 at 22:43
-
1@DDoSAttack but max priority is 999.. how they can use this figure that u had mentioned? – Noman Sep 29 '14 at 12:16
-
2@NomanHamid That is correct. 999 is the max priority. You can use whatever number you choose, Android will only guarantee up to 999 though. Anything larger than that and it may or may not be unstable and have unintended consequences. Personally, I had to use 2147483647 to try to go over apps like GO SMS PRO. Sometimes it worked for users and sometimes it didn't. – rf43 Sep 30 '14 at 19:42
-
@DDoSAttack Alright i got your point but it will be good if we follow guidelines :-) ... i have used 999 and its working fine for me in all cases. I appreciate you explanation. – Noman Oct 01 '14 at 12:31
/**
* Check priority
* @param activity
*/
public static void receiverPriority(Activity activity){
Intent smsRecvIntent = new Intent("android.provider.Telephony.SMS_RECEIVED");
List<ResolveInfo> infos = activity.getPackageManager().queryBroadcastReceivers(smsRecvIntent, 0);
for (ResolveInfo info : infos) {
System.out.println("Receiver: " + info.activityInfo.name + ", priority=" + info.priority);
}
}
Check priority and set higher priority (in your manifest) than other receivers.

- 1,068
- 12
- 11
If you have a scenario like this and you want to delete or ignore the message related to this contact number "+44xxxxx" etc, then use this code in SMS Broadcast receiver
if(sender.equalsIgnoreCase("+44xxxxxx")
this.abortBroadCast();
You also have to set it the high priority.

- 3,083
- 7
- 37
- 48

- 10,505
- 1
- 82
- 81