There are lots of examples on StackOverflow and elsewhere that use the class LocalBroadcastManager
to avoid broadcasting events outside of an app.
However, this class uses the Android support library as shown in the package name: android.support.v4.content.LocalBroadcastManager
.
Is there an equivalent of LocalBroadcastManager
in the standard SDK that does not use the Android support library?
It does not seem that the sendBroadcast
method in android.content.Context
has this kind of security granularity.
LocalBroadcastManager is used to register and send a broadcast of intents to local objects in your process. It has lots of advantages: You broadcasting data will not leave your app. So, if there is some leakage in your app then you need not worry about that.
LocalBroadcastManager is an application-wide event bus and embraces layer violations in your app: any component may listen events from any other.
No it doesn't exist, If you want to recreate this class you can read the source code to implement yourself without using the support lib. Anyway, what's the problem using the support lib? it's lightweight.
A bit workaround could be using the normal BroadCastReceiver and put <android:exported="false">
on your manifest, inside this receiver, this avoid to other apps send you intents, so you are faking a local receiver.
Note: I said faking, because the LocalBroadcastManager has optimizations, by not spread the intent to the system...
Hope this helps.
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