其他分享
首页 > 其他分享> > Android LocationManager.isProviderEnabled()始终返回false

Android LocationManager.isProviderEnabled()始终返回false

作者:互联网

我有一个应用程序,它使用网络提供程序的位置.每次应用程序启动时,它都会检查是否使用LocationManager中的isProviderEnabled()方法启用了网络提供程序.如果返回false,则向用户发出警报以启用网络提供程序,然后使用该应用程序.这个逻辑一直运行得非常好,除了一些非例外的非Google认证设备(因为它们通常也没有Maps API).最近,对于ICS上的一些设备,现在在JellyBean仿真器上,即使启用了isProviderEnabled(),我也会得到一致的“假”.

我已经转移到使用从返回的字符串
Settings.Secure.getString(getContentResolver(),Settings.Secure.LOCATION_PROVIDERS_ALLOWED))查看它是否包含“网络”.这是一个黑客,但它现在正在工作.我希望能够使用isProviderEnabled()方法.

以前有人看过这个问题吗?

解决方法:

来自API文档:LocationManager.GPS_PROVIDER

This provider determines location using satellites. Depending on
conditions, this provider may take a while to return a location fix.
Requires the permission ACCESS_FINE_LOCATION.

因此,如果您不需要ACCESS_FINE_LOCATION,它将返回false.

标签:android,locationmanager
来源: https://codeday.me/bug/20191002/1843304.html