1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| private void addLocationListener() {
Log.i("addLocationListener", "function is RUNNING!");
lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria c = new Criteria();
c.setAccuracy(Criteria.ACCURACY_FINE);
final Belgium bel = new Belgium();
final String PROVIDER = lm.getBestProvider(c, true);
final Location locGps = new Location(LocationManager.GPS_PROVIDER);
final Location locNet = new Location(LocationManager.NETWORK_PROVIDER);
this.myLocationListener = new MyLocationLinstener(getApplicationContext()) {
@Override
public void onLocationChanged(Location location) {
super.onLocationChanged(location);
// On recrée à chaque fois l'objet
mProgress = new ProgressTask(MainActivityTwo.this);
// On l'exécute
mProgress.execute();
//mProgress.cancel(true);
if (running == false) {
//destroy process..
mProgress.cancel(true);
running = true;
}
Toast.makeText(context, "Location changed", Toast.LENGTH_SHORT).show();
}
@Override
public void onProviderDisabled(String provider) {
super.onProviderDisabled(provider);
//Toast.makeText(context, "Gps Disabled", Toast.LENGTH_SHORT).show();
}
@Override
public void onProviderEnabled(String provider) {
super.onProviderEnabled(provider);
Toast.makeText(context, "Gps Enabled", Toast.LENGTH_SHORT).show();
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
super.onStatusChanged(provider, status, extras);
}
};
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
this.lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 60000, 0, this.myLocationListener);
} |
Partager