FusedLocationProviderClient всегда возвращает false в обратном вызове onLocationAvailability для Sony Xperia Z2.Разрешения предоставлены, местоположение включено.В настройках местоположения настроить вариант использования Wi-Fi, сети и GPS.Все отлично работает на эмуляторе, Samsung, BQ, Nexus, Xiaomi.Версии ОС от 6 до 8. Но на Sony (andorid 6.0.1) у меня такая проблема.Есть идеи ?Я закончил
Обратный звонок
private val mUserLocationCallback = object : LocationCallback() {
override fun onLocationAvailability(locationAvailability: LocationAvailability?) {
super.onLocationAvailability(locationAvailability)
val isAvalable = locationAvailability?.isLocationAvailable ?: false
if (!isAvalable) {
mLocationHelperListener.onLocationUnAvailable()
mDefaulLocation?.let { mLocationHelperListener.onLocationHelperChanged(it) }
stopLocationUpdates()
}
}
override fun onLocationResult(locationResult: LocationResult?) {
if (locationResult != null) {
for (location in locationResult.locations) {
mPreferences?.lastLatitude = location.latitude.toFloat()
mPreferences?.lastLongitude = location.longitude.toFloat()
mLocationHelperListener.onLocationHelperChanged(location)
stopLocationUpdates()
break
}
}
}
}
Запрос
val locationRequest = LocationRequest.create()
.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY)
.setInterval(UPDATE_INTERVAL)
.setFastestInterval(FASTEST_INTERVAL)
.setSmallestDisplacement(SMALLEST_DISTANCE)
// Create LocationSettingsRequest object using location request
val builder = LocationSettingsRequest.Builder()
builder.addLocationRequest(locationRequest)
val locationSettingsRequest = builder.build()
val settingsClient = LocationServices.getSettingsClient(mContext)
val task = settingsClient.checkLocationSettings(locationSettingsRequest)
task.addOnSuccessListener { locationSettingsResponse: LocationSettingsResponse? ->
mFusedLocationClient.requestLocationUpdates(locationRequest, mUserLocationCallback, null)
}
task.addOnFailureListener { exception: Exception ->
mLocationHelperListener.onLocationUnAvailable()
}