3

i have broadcast receiver class for receiving sms, but i dont know how to delete the received sms before reaching to the inbox as well as the notification

public void onReceive(Context context, Intent intent) {     
        Bundle pudsBundle = intent.getExtras();     
        Object[] pdus = (Object[]) pudsBundle.get("pdus");
        SmsMessage messages =SmsMessage.createFromPdu((byte[]) pdus[0]);        
        Log.i(TAG,  messages.getMessageBody());
}
Sujith PS
  • 4,776
  • 3
  • 34
  • 61
Arun
  • 1,167
  • 18
  • 37

2 Answers2

12

In your intent filter you should set the priority higher than the systems SMS-application.

<intent-filter android:priority="100" ...

And then in your broadcast receiver you call abortBroadcast()

   public void onReceive(Context context, Intent intent) {
     //... 
     abortBroadcast();
   }
MatteKarla
  • 2,707
  • 1
  • 20
  • 29
  • 3
    Won't this stop ALL broadcasts? he should have if intent.action().equals("WhateverTheActionIsCalled") – AndrewKS Oct 06 '10 at 18:36
  • Arun: Do you have a custom SMS-application installed? If that application have higher priority than your intent filter then they will recieve it first. try increasing the priority. Also if you don't return from `onRecieve()` quickly it could continue to the next broadcast reciever. – MatteKarla Oct 06 '10 at 20:02
  • 1
    Android priority not working for me here is the code iam using in mani fest file.. – Sando Jun 27 '11 at 10:39
  • is any permission required to use abortBroadcast();?? – Sando Jun 27 '11 at 10:39
  • @Sando: Try using android:priority="9999" – Sohaib Rahman Aug 09 '12 at 05:23
1
<receiver android:name=".SMSReceiver"
         android:permission="android.permission.BROADCAST_SMS"> 
        <intent-filter android:priority="999" > 
            <action android:name="android.provider.Telephony.SMS_RECEIVED" />
        </intent-filter>
</receiver>

and in receiver

  public void onReceive(Context context, Intent intent) {
     //... 
     abortBroadcast();
   }

This will work fine.

Sujith PS
  • 4,776
  • 3
  • 34
  • 61
Vinothkumar Arputharaj
  • 4,567
  • 4
  • 29
  • 36