简体   繁体   中英

Android Location network provider is always false

LocationManager locationManager= (LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
    boolean gpsIsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
    boolean networkIsEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);

    System.out.println("gpsIsEnabled  " +gpsIsEnabled +" \n networkIsEnabled  "+networkIsEnabled);

    if(networkIsEnabled)
    {
        location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
    }
    else if(gpsIsEnabled)
    {
        location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);  
    }

    System.out.println("Provider " + provider + " has been selected.");
    onLocationChanged(location);
    System.out.print(location.getLatitude());


<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

I am always getting false for network enabled when I have it enabled in my phone and I have also tried with wifi and it always false. I have tested with a galaxy S5 and always false.

必须打开位置设置才能使其正常工作。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM