Created
September 12, 2021 11:36
-
-
Save rahulsainani/aabcac3b39f663bd205ca07b30468a09 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
| /** | |
| * Find the closest Activity in a given Context. | |
| */ | |
| internal fun Context.findActivity(): Activity { | |
| var context = this | |
| while (context is ContextWrapper) { | |
| if (context is Activity) return context | |
| context = context.baseContext | |
| } | |
| throw IllegalStateException("Permissions should be called in the context of an Activity") | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment