FusedLocationProviderClient 在 Sony Xperia Z2 上的 onLocationAvailability 回调中总是 returns false

FusedLocationProviderClient always returns false in onLocationAvailability callback on Sony Xperia Z2

FusedLocationProviderClient 在 Sony Xperia Z2 上的 onLocationAvailability 回调中总是 returns false。授予权限,启用位置。在位置首选项中设置选项以使用 wifi、网络和 gps。在模拟器、三星、BQ、Nexus、小米上一切正常。 OS 版本从 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()
            }

我认为找到了解决方案。我认为我的解决方案适用于具有相同问题的其他设备。所以... 转到应用程序列表,找到 Google PLay 服务。打开权限。如果 "Location" 权限关闭 - 打开它。 如果没有这样的项目,请关闭所有项目,然后再打开。您应该会看到位置权限对话框。启用它,瞧,我的情况现在一切正常。

我有一个非常相似的问题;重新启动我的 phone 解决了这个问题。我在几台设备上进行了测试,但唯一有问题的设备是 ZTE Maven Z812。