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– jitter2009-11-16 11:42:04 +00:00Commented Nov 16, 2009 at 11:42
- 1Why would java be incorrect don't you program in java on Android?jitter– jitter2009-11-16 11:51:05 +00:00Commented Nov 16, 2009 at 11:51
- 3This reeks of evil. You shouldn't be doing this.MattC– MattC2009-11-17 03:14:29 +00:00Commented Nov 17, 2009 at 3:14
- 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– polyglot2010-08-04 14:15:29 +00:00Commented Aug 4, 2010 at 14:15
- 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– Felipe2011-10-08 00:11:57 +00:00Commented Oct 8, 2011 at 0: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
9 Comments
1000, so it is possible. In fact, Handcent are using priority 2147483647."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.".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
1 Comment
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.
7 Comments
/** * 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.