Created
June 22, 2020 12:14
-
-
Save robertlevonyan/91aae6a3633cce9fd39335a88850a533 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class HeadsetConnectionReceiver(private val actionPlugged: (Boolean) -> Unit) : BroadcastReceiver() { | |
override fun onReceive(context: Context?, intent: Intent?) { | |
intent?.run { | |
if (Intent.ACTION_HEADSET_PLUG == action) { | |
when (getIntExtra("state", -1)) { | |
0 -> actionPlugged(false) | |
1 -> actionPlugged(true) | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment