isProviderEnabled(LocationManager.NETWORK_PROVIDER)返回false

she*_*ell 13 android locationmanager android-location

我使用NETWORK_PROVIDER来获得latitudelongitude的地方.

我已经检查了"位置和安全性"中的设置并启用了"使用无线网络".但"isProviderEnabled(LocationManager.NETWORK_PROVIDER)"总是回来false.

谁能帮我?先感谢您!

这是我的代码:

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);
Run Code Online (Sandbox Code Playgroud)

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"/>
Run Code Online (Sandbox Code Playgroud)

Jer*_*rds 12

确保在手机设置中启用了基于网络的位置.您可以检测到这种情况,并在您确实需要时提示用户启用它.

我相信这是启动此活动的代码行.

activity.startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
Run Code Online (Sandbox Code Playgroud)

ACTION_LOCATION_SOURCE_SETTINGS

本文将其解释为http://emobiledude.com/fix-waiting-for-location-in-google-maps-after-android-4-2-update/

Android 4.0位置访问设置