isProviderEnabled(LocationManager.NETWORK_PROVIDER)返回falseLocationManager、isProviderEnabled、false、NE

2023-09-13 01:52:34 作者:芒果布丁萌嘟嘟耶i

我使用 NETWORK_PROVIDER 获得纬度经度。

我心中已经已经检查设置中的位置与安全性,并启用使用无线网络。但isProviderEnabled(LocationManager.NETWORK_PROVIDER)总是返回

谁能帮助我?预先感谢您!

下面是我的code:

  LocationManager locManager =(LocationManager)getSystemService(Context.LOCATION_SERVICE);
布尔isEnableGPS = locManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
布尔isEnableNTW = locManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
Log.d(TAG,isEnableGPS +,+ isEnableNTW);
 

在AndroidMainfest.xml许可

 <使用-权限的Andr​​oid:名称=android.permission.INTERNET对/>
<使用-权限的Andr​​oid:名称=android.permission.ACCESS_FINE_LOCATION/>
<使用-权限的Andr​​oid:名称=android.permission.ACCESS_COARSE_LOCATION/>
 

解决方案

确认,基于网络的位置在手机的设置中启用。您可以检测到这种情况并提示用户启用它,如果你真的需要它。

我相信这是code线,推出这一活动。

  activity.startActivity(新意图(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
 

ACTION_LOCATION_SOURCE_SETTINGS

这篇文章解释了它的http://emobiledude.com/fix-waiting-for-location-in-google-maps-after-android-4-2-update/

I am using NETWORK_PROVIDER to get latitude and longitude of the place.

I'v already check the setting in the "location & security" and enable "use wireless networks". But "isProviderEnabled(LocationManager.NETWORK_PROVIDER)" always return false.

Can anyone help me? Thank you in advance!

Here is my code :

LocationManager locManager=(LocationManager) getSystemService(Context.LOCATION_SERVICE);
boolean isEnableGPS=locManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
boolean isEnableNTW=locManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
Log.d(TAG, isEnableGPS+", "+isEnableNTW);

permission in the AndroidMainfest.xml

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

解决方案

Make sure that network based location is enabled in the phone's settings. You can detect this situation and prompt the user to enable it if you really need it.

I believe this is the line of code to launch this activity.

activity.startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);

ACTION_LOCATION_SOURCE_SETTINGS

This article explains it http://emobiledude.com/fix-waiting-for-location-in-google-maps-after-android-4-2-update/

 
精彩推荐
图片推荐