isProviderEnabled(LocationManager.NETWORK_PROVIDER) return false

若如初见. 提交于 2019-11-26 22:00:48

问题


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"/>

回答1:


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/



来源:https://stackoverflow.com/questions/10154937/isproviderenabledlocationmanager-network-provider-return-false

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!