0

我的以下代码适用于除 android 4.1 和 android 4.2 版本之外的所有设备。我已经尝试了很多东西并搜索了关于那个..在三星论坛中,它还说它不工作看到这个链接

 mLocationManager.requestLocationUpdates(
                LocationManager.NETWORK_PROVIDER,1000, 100, this);




public void onLocationChanged(Location newBestLocation) {

        System.out.println("On Location Change Call.......");
        mLocationManager.removeUpdates(this);
        boolean best = isBetterLocation(newBestLocation, currentLocation);
        if (best) {
            currentLocation = newBestLocation;
        }
        locationUpdater.onLocationUpdateReceived(currentLocation);
    }

如果有人知道解决方案,请告诉我。

4

1 回答 1

0

位置更新频率的 LocationManager 行为与 Android 4.1 中更改的 minTime 和 minDistance 参数有关。

http://developer.android.com/reference/android/location/LocationManager.html

在 Jellybean 之前,minTime 参数只是一个提示,一些位置提供程序实现忽略了它。从 Jellybean 及以后,Android 兼容设备必须遵守 minTime 和 minDistance 参数。

我怀疑您的 minDistance = 100 可能会导致 4.1 及更高版本缺少更新,而 Android 确实触发了 4.0 及更低版本的更新(可能不正确)。尝试将这两个值都更改为 = 0 看看会发生什么 - 你应该会经常看到更新:

mLocationManager.requestLocationUpdates(
            LocationManager.NETWORK_PROVIDER, 0, 0, this);

您必须使用这些参数,直到获得满足应用程序对位置更新频率的要求、同时延长电池寿命并在您想要支持的所有 Android 版本上具有一致行为的东西。

鉴于上述限制,您可能需要考虑切换到新的 Fused Location Provider:http: //developer.android.com/training/location/receive-location-updates.html

...更具体地说,PRIORITY_BALANCED_POWER_ACCURACY 优先级:http: //developer.android.com/reference/com/google/android/gms/location/LocationRequest.html#PRIORITY_BALANCED_POWER_ACCURACY

于 2013-07-03T20:14:41.293 回答