Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
fun Context.observeBroadcasts(action: String): Observable<Intent> {
return observeBroadcasts(IntentFilter(action))
fun Context.observeBroadcasts(intentFilter: IntentFilter): Observable<Intent> {
val observable = Observable.create<Intent> { observer ->
val receiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
observer.setDisposable(Disposables.fromRunnable {
registerReceiver(receiver, intentFilter)
return observable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment