Reputation: 10237
I want to watch for a particular SMS, and handle it in a Receiver when it arrives. I then want to "eat it" so that it doesn't bubble upwards and display to the user (it should be handled "silently"). Is this possible? If so, how?
Upvotes: 0
Views: 148
Reputation: 2579
Yes, it can be aborted by abortBroadcast() method and if you set priority of IntentFilter to 1000(highest priority) then this receiver will receive broadcast before the system.
Upvotes: 1
Reputation: 33741
I then want to "eat it" so that it doesn't bubble upwards and display to the user (it should be handled "silently")
Huh? Intents that you register to receive are handled silently unless you choose to handle it "loudly".
EDIT
Also, there is no way to prevent other apps from responding to SMS messages. Think about the security implications of allowing one app to control whether other apps can listen for system events...
Upvotes: 1
Reputation: 1006614
Is this possible? If so, how?
Since the SMS broadcast happens to be an ordered broadcast, your BroadcastReceiver
can call abortBroadcast()
to stop it from being handled by lower-priority receivers.
Here is a blog post from a while back discussing ordered broadcasts. Here is a sample project based upon that blog post. Here is a sample SMS BroadcastReceiver
that conditionally executes abortBroadcast()
.
Upvotes: 4
Reputation: 18725
You are looking for the Service construct in Android. It is designed to run something, without requiring a UI (like an Activity).
BroadcastReceiver is additional functionality you should research to catch the SMS event.
Upvotes: 1