tags:

views:

53

answers:

1

Hello all

In my android application that is now working fine, I am sending custom SMS from a user to other one.

Once I detect the SMS come from my application, I do my stuff with the message and everything work fine.

But now, I do not want the SMS application to detect this message as it is totally useless for the user.

So what I would like to do: As soon I receive it, I get the text and avoid the system to get it ( or at least stop the notification for this message)

Any Idea on how to do?

Here is my current code:

(EDIT: Sorry for the formatting, I cannot understand how that work!)

public class SmsReceiver extends BroadcastReceiver {

@Override

public void onReceive(Context context, Intent intent) {

// ---get the SMS message passed in---

Bundle bundle = intent.getExtras();

SmsMessage[] msgs = null;

String str = "";

 if (bundle != null) {

// ---retrieve the SMS message received---

Object[] pdus = (Object[]) bundle.get("pdus");

msgs = new SmsMessage[pdus.length];

String number = "";

String body = "";

for (int i = 0; i < msgs.length; i++) {
    msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
    number = msgs[i].getOriginatingAddress();
    body = msgs[i].getMessageBody().toString();
    str += "SMS from " + number;
    str += " :";
    str += body;
    str += "\n";
   }
If(detectIfSmsComeFromMyApplication)
// DELETE MESSAGE AND AVOID BROADCAST.
// MAKE IT INVISIBLE TO USER

}

} }

+1  A: 

Take a look at the first answer on this question: can-we-delete-an-sms-in-android-before-it-reaches-the-inbox

Soldier.moth
Ok, thank for the answer, perfect!
Profete162