My application requires that the user have Improved Location Accuracy turned on in their settings. Unfortunately, I can't figure out the correct way to actually get to the right menu, and have the back button return to my application once the setting is set.
Here is what I have:
private fun checkLocationSettingsAsync() {
viewModel.launch(Dispatchers.IO) {
val locationSettings = client.checkLocationSettings(
locationBuilder.build()
).asDeferred()
locationSettings.asTask().addOnSuccessListener {
//location settings are already high accuracy
locationSettingsOkay = true
}.addOnFailureListener { e ->
if (e is ResolvableApiException) {
//location settings not satisfied, request to make them higher
runCatching {
val intent = Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS)
startActivityForResult(intent, LOCATION_ACCURACY_ACCESS_CODE)
}.onFailure {
println(it.stackTrace)
}
}
}
locationSettings.await()
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
when (requestCode) {
LOCATION_ACCURACY_ACCESS_CODE -> {
if (resultCode == Activity.RESULT_OK) {
//TODO: navigate back to activity once setting is set
}
}
}
}
The Android menu Settings.ACTION_LOCATION_SOURCE_SETTINGS gets to the outer menu that contains the Improved Location Accuracy setting, but I can't actually find the correct Intent name to get to the appropriate menu, nor can I get it so that the user can navigate back to my application when the setting is enabled.
Any advice? Or documentation, since I can't find anything about this!
EDIT: here is a good code sample! https://github.com/googlesamples/android-play-location/blob/master/LocationUpdates/app/src/main/java/com/google/android/gms/location/sample/locationupdates/MainActivity.java