用于 GPS 的 IsProviderEnabled 不起作用

Kas*_*sas 4 gps android

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

manager.isProviderEnabled( LocationManager.GPS_PROVIDER )
Run Code Online (Sandbox Code Playgroud)

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

你知道发生了什么吗?

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

小智 5

您可以直接从系统获取 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);
} 
Run Code Online (Sandbox Code Playgroud)