安卓LocationManager.isProviderEnabled()总是返回false [英] Android LocationManager.isProviderEnabled() always returns false

查看:5221
本文介绍了安卓LocationManager.isProviderEnabled()总是返回false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有使用网络服务提供者为它的位置的应用程序。每次在应用程序启动时,它会检查使用isProviderEnabled()方法,LocationManager网络服务提供者是否启用。如果它返回false我present警报给用户,使网络供应商,然后使用该应用程序。这个逻辑已经工作真的很好,也有少数例外与非谷歌认证的设备(因为不是一个问题,他们通常没有地图API两种)。最近,对ICS的软糖模拟器一些设备,现在我得到一个一致的假的isProviderEnabled(),即使它被启用。

I have an application which uses Network provider for it's location. Everytime the apps starts it checks to see whether Network provider is enabled using isProviderEnabled() method in LocationManager. If it returns false I present an alert to the user to enable Network Provider and then use the application. This logic had been working really well, with a few exceptions with non-Google certified devices(not a concern since, they usually do not have Maps API either). Lately, with some devices on ICS and now on JellyBean emulator I get a consistent "false" for isProviderEnabled() even though it is enabled.

因为我已经搬到了利用返回的字符串 Settings.Secure.getString(getContentResolver(),Settings.Secure.LOCATION_PROVIDERS_ALLOWED)),看看它是否包含网。这是一个黑客,但它是工作现在。我很想能够使用isProviderEnabled()方法。

I have since moved to using the string returned from Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED)) to see whether it contains "network". It is a hack but it is working for now. I would love to be able to use isProviderEnabled() method.

在有没有人看到这个问题?

Has anyone see this issue before?

推荐答案

如果您确定网络位置是您的手机上启用 isProviderEnabled(LocationManager.NETWORK_PROVIDER)将返回false,因为您使用此呼叫您的位置经理尚未正确初始化。所以,你必须要做到这一点:

If you are sure that network location is enabled on your phone isProviderEnabled(LocationManager.NETWORK_PROVIDER)is returning false because your location manager that you are using for this call hasn't been initialized properly. So you have to do this:

LocationManager locManager =  (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
networkEnabled = locManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);

这篇关于安卓LocationManager.isProviderEnabled()总是返回false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆