in my onReceive method I have this code:
if (from.equals(number)) {
abortBroadcast();
in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(in);
Toast.makeText(context, str, Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(context, "Not from needed number", Toast.LENGTH_SHORT).show();
}
where number = "29853" are the numeric messages from which I want to catch and not save in the inbox.
This code works correctly - if the SMS is from the number on which the first Toast works, and it prints the contents of the message, if the SMS is not from the "Not from the right number" number. The problem is that abortBroadcast is not doing its job - the message from the number is still in the phone’s inbox, although the priority of the receiver is 1000:
<receiver android:name=".service_classes.MyReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED"
android:priority="1000" />
</intent-filter>
</receiver>
What is the problem - why does abortBroadcast not work?
source
share