Back to project page EnergyWastingApp.
The source code is released under:
Copyright ? 2013-2014 Pekka Ekman <pekka.ekman@aalto.fi> 2013 Babujee Jerome Robin <robin.babujeejerome@aalto.fi> Permission is hereby granted, free of charge, to any person obtaining a ...
If you think the Android project EnergyWastingApp listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package fi.aalto.pekman.energywastingapp.components; // www . j a v a 2s . c o m import android.content.Context; import android.content.Intent; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.util.Log; public class GPSCoordSearch extends Component implements LocationListener{ private static LocationManager lm = null; private static boolean running = false; @Override public String getName() { return "GPSSearch"; } @Override public void start() { lm = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE); if(lm.isProviderEnabled(LocationManager.GPS_PROVIDER)){ markTurnedOn(); running = true; lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); } else { context.startActivityForResult(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS), 100); if(lm.isProviderEnabled(LocationManager.GPS_PROVIDER)){ running = true; markTurnedOn(); lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); } else { running = false; Log.e("GPSCoordSearch", "GPS cannot be turned on!"); markTurnedOff(); } } } @Override public void stop() { if(null != lm && GPSCoordSearch.running){ lm.removeUpdates(this); markTurnedOff(); } } @Override public void onPause() { if(!GPSCoordSearch.running){ markTurnedOff(); } } @Override public void onLocationChanged(Location location) { } @Override public void onProviderDisabled(String provider) { } @Override public void onProviderEnabled(String provider) { } @Override public void onStatusChanged(String provider, int status, Bundle extras) { } }