Reputation: 11908
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" - number messages from which I wanna catch and not save in Inbox.
This code works correctly - if sms is from number the first Toast works and it prints the content of the message, if sms is not from number "Not from needed number" is printed. The problem is that abortBroadcast doesn't make its businness - the message from number is still in the Inbox of the phone although receiver's priority 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's the problem - why doesn't abortBroadcast work?
Upvotes: 6
Views: 14597
Reputation: 44968
From Android 4.4 you cannot abort these broadcasts. Here's a link to the AOSP sources that show this:
Upvotes: 4
Reputation: 81
move the android:priority
to the intent-filter where it belongs.
<intent-filter android:priority="9999999">
then you will more likely have priority and your canceling will work. I have tested it and it does work.
Upvotes: 8
Reputation: 11
I've used this a while ago and it was working, I could reject some messages to show-up but this doesn't work now. I think android no longer lets user take all control over SMS_RECEIVED event.
Upvotes: 1