Java

public class MainActivity extends AppCompatActivity implements LocationListener{ private LocationManager locationManager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,2000, 1, this); } @Override public void onLocationChanged(Location location) { String msg = "New Latitude: " + location.getLatitude() + "New Longitude: " + location.getLongitude(); Toast.makeText(getBaseContext(), msg, Toast.LENGTH_LONG).show(); } @Override public void onProviderDisabled(String provider) { Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivity(intent); Toast.makeText(getBaseContext(), "Gps is turned off!! ", Toast.LENGTH_SHORT).show(); } @Override public void onProviderEnabled(String provider) { Toast.makeText(getBaseContext(), "Gps is turned on!! ", Toast.LENGTH_SHORT).show(); } @Override public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } } 

Manifest

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

I check on the emulator. If you use GPS_Provider then it works. But I need to use only NETWORK_PROVIDER. Therefore ACCESS_FINE_LOCATION indicated.

But nothing works. What do guys do ????

The whole day is already on the nerves. Well, what kind of people these developers Google (((

    1 answer 1

    Add to manifest:

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

    Edit: requestLocationUpdates(LocationManager.NETWORK_PROVIDER,2000, 1, this);

    On: requestLocationUpdates(LocationManager.NETWORK_PROVIDER,2000, 0, this);

    • My ACCESS_FINE_LOCATION is already Andro
    • @xTIGRx, updated the answer - redL1ne
    • Yes, at least -100 still does not work, I checked. You open AS and try what they said)). Check it out - Andro
    • @xTIGRx, works on the phone - redL1ne
    • And what kind of phone do you have? on my not plowing - Andro