android – LocationAvailability没有位置

前端之家收集整理的这篇文章主要介绍了android – LocationAvailability没有位置前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

谷歌的FusedLocationProviderApi for Android最近在过去几个月内被弃用,其中FusedLocationProviderClient是其继任者,因此我最近更新了客户端应用程序中使用的位置API以使用新的API.

每次在LocationCallback中触发onLocationAvailability时,我会在locationAvailability.isLocationAvailable()返回false时通知用户,但看起来这种情况比某些设备上的预期更频繁.我在前台服务中运行这些位置更新,这些位置更新保持一致至关重要.有没有办法确定这种失败的原因

>我们不会向最终用户表明任何误报
>我们可以尝试解决问题,或者至少向最终用户报告他们应该做什么?

在我看来,被弃用的API提供了对这些问题的更多洞察,因为它与GoogleApiClient一起使用,或者我可能缺少一些较小的细节.

最佳答案
official documentation says

onLocationAvailability Called when there is a change in the
availability of location data. When isLocationAvailable() returns
false you can assume that location will not be returned in
onLocationResult(LocationResult) until something changes in the
device’s settings or environment.
Even when isLocationAvailable()
returns true the onLocationResult(LocationResult) may not always be
called regularly,however the device location is known and both the
most recently delivered location and getLastLocation(GoogleApiClient)
will be reasonably up to date given the hints specified by the active
LocationRequests.

因此,此方法不提供有关原因的信息.

>我们不会向最终用户表明任何误报

>目前我只是忽略了这个方法的结果,因为它经常返回false,然后再次返回true,依此类推.

>我们可以尝试解决问题,或者至少向最终用户报告他们应该做什么?

>检查是否启用了位置服务(使用LocationManager.isProviderEnabled())
>检查您是否拥有权限,如果需要请求它们(docs)

原文链接:https://www.f2er.com/android/430175.html

猜你在找的Android相关文章