Created
November 14, 2019 13:22
-
-
Save lucassales2/381fcf666a85f9ac4a304a713f3b0a1c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Suppress("FunctionName") | |
fun BroadcastReceiverFlow(c: Context, intentFilter: IntentFilter): Flow<Intent> { | |
return callbackFlow { | |
val broadcastReceiver = object : android.content.BroadcastReceiver() { | |
override fun onReceive(context: Context, intent: Intent) { | |
offer(intent) | |
} | |
} | |
c.registerReceiver(broadcastReceiver, intentFilter) | |
awaitClose { c.unregisterReceiver(broadcastReceiver) } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment