LocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)是不可靠的,为什么呢?什么呢、不可靠、LocationManage

2023-09-06 02:42:25 作者:看你远走i

我的应用程序的一个用户报告说,应用程序告诉网络位置处于关闭状态,即使他没有打开它。他给我发了一些屏幕截图,他们让我想起;

One user of my app reported that app tells network for location is off even he did turn it on. He sent me few screen shots and they made me think;

LocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)

不能正常工作。他的手机运行的是Android 4.1.2,并开始我以为this是这个问题的原因。但是它不是这样的。他给我发了一个截屏的设置了。

is not working properly. His phone is running Android 4.1.2 and first I thought this is the cause of this issue. But it was not the case. He sent me a screen shot of that setting too.

然后,我用Google搜索,发现this.这个问题似乎帮助我,但遗憾的是答案是不是这种情况下有益的提问没有追求更远。

Then I googled and found this. The question seems to help me but unfortunately answer was not helpful for this case and questioner did not pursue farther.

我的应用程序相关的位置,并一直使用LocationManager.isProviderEnabled知道GPS和网络的位置是打开或关闭。我从来没有告诉我的应用程序不能正确认识这些设置,直到最近。他是谁报告的问题的第一个用户。我了解到有其他方法来知道全球定位系统和网络的位置设置,通过看Secure.LOCATION_PROVIDERS_ALLOWED。要了解他的电话这个方法的工作,我写了简单的应用程序,并要求他跑。这个应用程序做简单的任务,并显示在屏幕上的文字。

My app is related to location and have been using LocationManager.isProviderEnabled to know GPS and Network for location is on or off. I have never been told my app is not properly knowing those settings until recently. He is the first user who reported the issue. I learned there are another method to know GPS and Network for location settings, by seeing Secure.LOCATION_PROVIDERS_ALLOWED. To see how this method work on his phone, I wrote simple app and asked him to run. This app does simple task and shows text on screen.

LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
if(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
{
    string = "GPS=on\n";
}
else
{
    string = "GPS=off\n";
}
if(locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
{
    string += "Network=on\n";
}
else
{
    string += "Network=off\n";
}
String status = android.provider.Settings.Secure.getString(getContentResolver(), Secure.LOCATION_PROVIDERS_ALLOWED);
if(status.contains("gps"))
{
    string += "GPS=on\n";
}
else
{
    string += "GPS=off\n";
}
if(status.contains("network"))
{
    string += "Network=on\n";
}
else
{
    string += "Network=off\n";
}

他送回屏幕再次出手。它看起来;

He sent back screen shot again. It looks;

GPS=on
Network=off
GPS=on
Network=on

这个结果并没有使我快乐。可能有一些可能性这一点。

This result did not make me happy. There could be some possibilities for this.

当其他人之前的质疑,这个问题一直存在在某些手机上。 在谷歌打破了这一4.1.2。 isProviderEnabled不能在此版本的工作。 虽然没有记载,从4.1.2,isProviderEnabled不会像以前那样工作。 不,谷歌改变任何东西。这是这个特殊的电话一个错误。

现在我的问题是;

是LocationManager.isProviderEnabled仍然有效为Android 4.1.2及以后呢? 是否看到Secure.LOCATION_PROVIDERS_ALLOWED有一些缺点/坑孔(当我放弃了使用LocationManager.isProviderEnabled?

在此先感谢。

EDIT1:

Here你可以从谷歌测试应用程序播放尝试或问别人去尝试。

Here you can download test app from Google Play to try or ask someone to try.

EDIT6:

我删除测试应用程序,因为这个问题的回答。

I removed test app since this question is answered.

EDIT2:

我发表我的应用程序,它检查网络供应商是看到Secure.LOCATION_PROVIDERS_ALLOWED使用,并且在有限的手机有异常。 这些都是ACRA的报告。

I released my app which checks network provider is usable by seeing Secure.LOCATION_PROVIDERS_ALLOWED and got exception on limited phones. These are ACRA's report.

一些手机上运行OS 4.1.1。

Some phone running OS 4.1.1.

java.lang.IllegalArgumentException: requested provider network doesn't exisit
    at android.os.Parcel.readException(Parcel.java:1434)
    at android.os.Parcel.readException(Parcel.java:1384)
    at android.location.ILocationManager$Stub$Proxy.requestLocationUpdates(ILocationManager.java:675)
    at android.location.LocationManager._requestLocationUpdates(LocationManager.java:686)
    at android.location.LocationManager.requestLocationUpdates(LocationManager.java:508)

一些手机上运行OS 4.1.2。

Some phone running OS 4.1.2.

java.lang.IllegalArgumentException: provider=network
    at android.os.Parcel.readException(Parcel.java:1439)
    at android.os.Parcel.readException(Parcel.java:1389)
    at android.location.ILocationManager$Stub$Proxy.requestLocationUpdates(ILocationManager.java:659)
    at android.location.LocationManager._requestLocationUpdates(LocationManager.java:690)
    at android.location.LocationManager.requestLocationUpdates(LocationManager.java:512)

我从来没有见过的那些异常,直到我换了一个方法来检查网络供应商的位置可用与否。所以我觉得LocationManager.isProviderEnabled是安全的,看到Secure.LOCATION_PROVIDERS_ALLOWED是有风险的。但是,这将让我回到原来的问题。为什么LocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)返回false(而且是不是真的),当Secure.LOCATION_PROVIDERS_ALLOWED告诉有。的是Android OS设计不当?还是我刚才看见拴只对特定问题(但也有至少2人)电话?

I have never seen those exceptions until I changed a method to check network provider for location is usable or not. So I think LocationManager.isProviderEnabled is safe and seeing Secure.LOCATION_PROVIDERS_ALLOWED is risky. But this will put me back to original issue. Why LocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER) returns false (and there is not really) when Secure.LOCATION_PROVIDERS_ALLOWED tells there IS. Is Android OS poorly designed? Or I have just seeing issues tied only to specific (but there are at least 2 of them) phones?

EDIT3:

我更新了测试程序,以显示GPS /网络位置提供商似乎真的可用或不通过访问与requestLocationUpdates()。

I updated test app to show GPS/Network location provider seems really usable or not by accessing with requestLocationUpdates().

和我透露2手机的名字。

And I disclose 2 phones name.

1)SBM200SH,OS4.1.2,软银移动,夏普公司 2)HTX21(INFOBAR A02),OS4.1.1,KDDI,宏达电

1) SBM200SH, OS4.1.2, Softbank mobile, Sharp Corporation 2) HTX21 (INFOBAR A02), OS4.1.1, KDDI, HTC

EDIT4:

我发现3的电话。

3)SBM203SH,OS4.1.2,软银移动,夏普公司

3) SBM203SH, OS4.1.2, Softbank mobile, Sharp Corporation

EDIT5:

夏普公司正在运行的讨论空间,为移动开发者。我贴主题由presenting这个SO的问题。我希望有人在夏普公司采取行动这一点。我会保持这个更新。

Sharp Corporation is running discussion space for mobile developers. I posted topic by presenting this SO's question. I hope someone at Sharp Corporation takes action for this. I will keep this updated.

推荐答案

由夏普公司提供的开发人员支持非常好,他们在不到48小时回答了我的问题。

Developer support provided by Sharp corporation is excellent and they answered to my question in less than 48 hours.

这是我从他们身上得到的。

This is what I got from them.

有2个条件必须得到​​满足的LocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)返回true。

There are 2 conditions must be met that LocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER) returns true.

在一些内部状态是准备网络位置。 在网络位置上设置屏幕中启用。

其次一个是显而易见的。但是,第一个是没有。他们告诉如何模拟第一种是消极的。可以确认的步骤问题,如下图所示,并运行我的测试应用程序(请参阅我的问题的链接下载)。

Second one is obvious. But first one is not. They told how to simulate first one is negative. You can confirm the issue with steps shown below and running my test app (please see my question for link to download).

你打开手机的设置。 点击应用。 点击所有的标签。 找到网络位置,点击它。 点击禁用。 重新启动手机。 运行测试程序。

有关原因,我无法理解用户的手机没有做一些相关的首要条件上面显示和表现出的问题。

For reason I can't understand the user's phone failed to do something related to first condition shown above and exhibits the issue.

结论:

LocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)是可靠的。而且要注意,Secure.LOCATION_PROVIDERS_ALLOWED是不可靠的。

LocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER) is reliable. And be aware, Secure.LOCATION_PROVIDERS_ALLOWED is less reliable.

 
精彩推荐
图片推荐