gpt4 book ai didi

android - getLastKnownLocation 不适用于 Samsung Galaxy S3 4.0.4

转载 作者:行者123 更新时间:2023-11-29 02:00:17 26 4
gpt4 key购买 nike

我有一些已使用多年的 getLastKnowLocation 代码,但它不适用于 Samsung Galaxy S3 4.0.4。

Location location = null;

locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, true);
// The S3 returns null here (even though location is enabled), google maps works.
try {
location = locationManager.getLastKnownLocation(provider);
} catch (IllegalArgumentException e) {

}
if ( location == null ) { // only S3 gets this....
location = locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
}

我注意到,如果我添加 PASSIVE_PROVIDER,我会得到一个位置,但我从来没有得到任何 onLocationChanged。相同的代码适用于我从 2.1 到 4.1 测试过的所有系统(我的 CM10 除外,它看起来更加困惑)

对正在发生的事情有什么想法吗?错误/功能?

我发现其他人也有类似的问题No GPS location updates on Galaxy S3

最佳答案

这与 Android 版本无关,我的代码适用于 Galaxy Nexus 4.2.2 而不是 S3 4.1 或 Sony XPeria S 4.0.4

我怀疑 GPS 位置没有检测到您(这需要时间和良好的 GPS 信号),在我的应用程序中,当我发现 GPS 没有响应或未启用时,我切换到网络检测(~45 米精度不是那个对于我必须在 10 公里半径内搜索设备的情况来说很糟糕)

关于android - getLastKnownLocation 不适用于 Samsung Galaxy S3 4.0.4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13017219/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com