Created
January 18, 2014 03:17
-
-
Save anonymous/8485685 to your computer and use it in GitHub Desktop.
Capturando localização em uma aplicação android à partir de todos os providers disponíveis.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.auad.gpsoptimization; | |
import android.location.Location; | |
import android.location.LocationListener; | |
import android.location.LocationManager; | |
import android.os.Bundle; | |
import android.app.Activity; | |
import android.util.Log; | |
import android.view.Menu; | |
public class MainActivity extends Activity implements LocationListener{ | |
private LocationManager locationManager; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); | |
for(String providerName : locationManager.getAllProviders()) { | |
if(locationManager.isProviderEnabled(providerName)) { | |
locationManager.requestLocationUpdates(providerName, 0, 0, this); | |
} | |
} | |
} | |
@Override | |
public boolean onCreateOptionsMenu(Menu menu) { | |
// Inflate the menu; this adds items to the action bar if it is present. | |
getMenuInflater().inflate(R.menu.main, menu); | |
return true; | |
} | |
@Override | |
public void onLocationChanged(Location location) { | |
Log.i("GPS_TEST", location.getProvider() + "(" + location.getTime() + ")"+ ": " + location.getLatitude() + " -- " + location.getLongitude()); | |
} | |
@Override | |
public void onProviderDisabled(String provider) { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public void onProviderEnabled(String provider) { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public void onStatusChanged(String provider, int status, Bundle extras) { | |
// TODO Auto-generated method stub | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment