Я использую этот код в качестве BroadcastReceiver:
public void onReceive(Context context, Intent intent)
{
//this stops notifications to others
this.abortBroadcast();
//---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];
for (int i=0; i<msgs.length; i++){
msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
str += "SMS from " + msgs[i].getOriginatingAddress();
from = msgs[i].getOriginatingAddress();
str += " :";
str += msgs[i].getMessageBody().toString();
msg = msgs[i].getMessageBody().toString();
str += "\n";
}
if(checksomething){
//make your actions
//and no alert notification and sms not in inbox
}
else{
//continue the normal process of sms and will get alert and reaches inbox
this.clearAbortBroadcast();
}
}
не забудьте добавить его в манифест и добавить наивысший приоритет (100) для широковещательной рассылки, или смс отправится первым во входящие и получит уведомление о предупреждении.
<receiver android:name=".SmsReceiver">
<intent-filter android:priority="100">
<action android:name="android.provider.Telephony.SMS_RECEIVED"></action>
</intent-filter>
</receiver>
Надеюсь, это поможет вам.