LocationManager gives NETWORK_PROVIDER disabled

核能气质少年 提交于 2019-12-24 00:48:45

问题


I need to retrieve user's location by 3G or WIFI.

This is what I'm trying to do:

LocationListener locationListener = new LocationListener() {
            public void onLocationChanged(Location location) {
                manageLocation(location);
            }

            public void onStatusChanged(String provider, int status, Bundle extras) {

            }

            public void onProviderEnabled(String provider) {

            }

            public void onProviderDisabled(String provider) {

            }
        };
        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);

The problem is that the only callback that is called is onProviderDisabled giving LocationManager.NETWORK_PROVIDER as parameter.

I've got that permission in the manifest:

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

How can I enable that type of location in my application?


回答1:


The user needs to go into the device's Settings app and enable location providers. You cannot enable that yourself directly.



来源:https://stackoverflow.com/questions/37440189/locationmanager-gives-network-provider-disabled

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