gpt4 book ai didi

android - GPS 的 IsProviderEnabled 不起作用

转载 作者:太空狗 更新时间:2023-10-29 12:51:59 25 4
gpt4 key购买 nike

我们已经为 Android 实现了基于地理的应用程序,因此我们需要确保始终启用 GPS。问题是

manager.isProviderEnabled( LocationManager.GPS_PROVIDER )

即使启用了 GPS 提供程序,它也始终返回 false,因此我们的应用程序始终显示更改 GPS 状态的警报或它不工作。

你知道发生了什么吗?

我们正在使用 Samsung Galaxy S 和 HTC Wildfire 设备对其进行测试...提前致谢。

最佳答案

您可以直接从系统获取 GPS 状态:

LocationManager myLocationManager = (LocationManager)  getSystemService(Context.LOCATION_SERVICE);

private boolean getGPSStatus()
{
String allowedLocationProviders =
Settings.System.getString(getContentResolver(),
Settings.System.LOCATION_PROVIDERS_ALLOWED);

if (allowedLocationProviders == null) {
allowedLocationProviders = "";
}

return allowedLocationProviders.contains(LocationManager.GPS_PROVIDER);
}

关于android - GPS 的 IsProviderEnabled 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11341771/

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