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 (((