package com.twormobile.itrackmygps;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationManager;
import com.twormobile.itrackmygps.android.Log;
public class LocationReceiver extends BroadcastReceiver {
private static final String TAG = "LocationReceiver";
@Override
public void onReceive(Context context, Intent intent) {
// If you got a Location extra, use it
Location loc = (Location)intent.getParcelableExtra(LocationManager.KEY_LOCATION_CHANGED);
int ctr = intent.getIntExtra("counter", 0);
if (loc != null) {
onLocationReceived(context, loc, ctr);
return;
}
// If you get here, something else has happened
if (intent.hasExtra(LocationManager.KEY_PROVIDER_ENABLED)) {
boolean enabled = intent.getBooleanExtra(LocationManager.KEY_PROVIDER_ENABLED, false);
onProviderEnabledChanged(enabled);
}
}
protected void onLocationReceived(Context context, Location loc, int ctr) {
Log.d(TAG, this + " Got #" + Integer.toString(ctr) + " location from " + loc.getProvider() + ": "
+ loc.getLatitude() + ", " + loc.getLongitude());
}
protected void onProviderEnabledChanged(boolean enabled) {
Log.d(TAG, "Provider " + (enabled ? "enabled" : "disabled"));
}
}