There's several examples of how to read SMS's in a Broadcast Receiver with a high priority, and then call abortBroadcast() to stop the intent from reaching other applications' broadcast receivers. However, none of them seem to take into account the fact that there could be multiple SMS's in the intent's data, so calling abortBroadcast() kills all SMS's essentially in that specific intent.
I'm trying to create an application that blocks texts from certain numbers, and obviously this is an issue when I get two messages in one intent, one being from a blocked number, and one being from an unblocked number.
Is there a way to create a new Intent and re-broadcast one or more of the SMS's from the original intent received, so that messages I don't want to block can carry on to whatever apps are expecting them?
I was just researching this same problem and I think (not positive) that the answer is very simple.
A broadcast contains an array of SmsMessage objects because large messages need to be broken into multiple smaller messages. But it's still one text message.
You may recognize the following code:
Object[] pdus = (Object[]) bundle.get("pdus");
SmsMessage[] msgs = new SmsMessage[pdus.length];
A PDU is a "Protocol Description Unit", which is the industry standard for SMS messages. A large message needs to be broken into several smaller messages, which is why it is an array of objects.
So I think the answer is that you will never cancel more than one text message when you call abortBroadcast().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With