Broadcast Receivers
A BroadcastReceiver is an Android component that:
Listens for broadcast messages (called Intents)
Reacts to system-wide or app-wide events
Does not have a UI
A broadcast is just an Intent sent out to multiple potential listeners.
Examples of events that trigger broadcasts:
Device boot completed
Battery low / battery okay
Network connectivity changed
SMS received
Screen on / off
App-specific events (your own custom broadcasts)
Android apps can send or receive broadcast messages from the Android system and other Android apps, similar to the publish-subscribe pattern.
Types of Broadcast Receivers
1. Manifest-declared (Static Receivers)
Declared in AndroidManifest.xml
Used when:
You need to receive events even when the app is not running
Important Android reality check:
Since Android 8.0 (API 26), most implicit broadcasts cannot be registered in the manifest anymore.
Still allowed:
BOOT_COMPLETEDSMS_RECEIVEDSome system-critical broadcasts
2. Context-registered (Dynamic Receivers)
Registered at runtime using code.
Registering the Receiver:
Broadcast Receiver:
Unregistering the Receiver:
Types of Broadcasts
System Broadcasts
Sent by Android OS.
Custom Broadcasts
APP Sending Custom Broadcast:
APP Receiving Custom Broadcast:
Registering the receiver:
Broadcast Receiver:
Unregistering the receiver:
Types of Broadcast delivery
1. Normal Broadcast
Delivered to all matching receivers
Order is not guaranteed
Fast, simple, chaotic
2. Ordered Broadcast (mostly legacy now)
Delivered one receiver at a time
Receivers can:
Modify the Intent
Abort the broadcast
Used in the past for SMS filtering and similar things.
Modern Android discourages this.
3. Local Broadcast (Deprecated)
Only within your app
More efficient
No security risk
Now deprecated because: we can use LiveData, Flow, SharedViewModel, or RxJava
onReceive() rules
Inside onReceive():
❌ No long-running tasks
❌ No network calls
❌ No sleep
❌ No heavy database operations
Otherwise, app can get killed or get an ANR.
Allowed:
Quick checks
Logging
Starting a Service
Scheduling work
Protected Broadcasts
A protected broadcast is a system-level broadcast that third-party apps are NOT allowed to send.
You can receive it
You cannot send it
Android enforces this at runtime
Violate it and Android throws a SecurityException
Example:
If your app tries:
Without protected broadcasts:
Any app could pretend the phone rebooted
Fake incoming SMS
Trigger system alarms
Mess with power, connectivity, or security flows
Explicit Broadcasts
Goes to one specific receiver
No intent filters involved
Implicit Broadcasts
Goes to all matching receivers
This is where protected broadcasts matter
Restricted heavily since Android 8.0
Restrict broadcasts with permissions
They are called Permission-Protected Broadcasts.
Here, sending or receiving requires a permission.
Permissions allow you to restrict broadcasts to the set of apps that hold certain permissions.
You can enforce restrictions on either the sender or receiver of a broadcast.
Only receivers who have requested that permission with the <uses-permission> tag in their manifest can receive the broadcast.