Last active
October 27, 2022 12:08
-
-
Save inderisonline/edf56f6adfe232960db6e8eab11768bc to your computer and use it in GitHub Desktop.
CurrentLocationCoroutineWrapperImpl test example
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
class CurrentLocationCoroutineWrapperImpl( | |
private val fusedLocationProviderClient: FusedLocationProviderClient | |
) { | |
@RequiresPermission( | |
anyOf = | |
[ | |
Manifest.permission.ACCESS_FINE_LOCATION, | |
Manifest.permission.ACCESS_COARSE_LOCATION | |
] | |
) | |
suspend fun getCurrentLocation(priority: Int) = | |
suspendCancellableCoroutine { cont -> | |
fusedLocationProviderClient.getCurrentLocation( | |
priority, null | |
).apply { | |
addOnSuccessListener { location: Location? -> | |
if (location == null) { | |
cont.resumeWithException(LocationNotFoundException()) | |
} else { | |
cont.resume(location) | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment