Subversion Repository Public Repository

Nextrek

Diff Revisions 521 vs 522 for /Android/SmartCharging/SmartCharging/app/src/main/java/it/fedeloper/smartcharging/Manager/MyLocation.java

Diff revisions: vs.
  @@ -11,6 +11,8 @@
11 11 import android.location.LocationListener;
12 12 import android.location.LocationManager;
13 13 import android.os.Bundle;
14 + import android.widget.Toast;
15 + import it.fedeloper.smartcharging.R;
14 16
15 17 import java.io.IOException;
16 18 import java.util.List;
  @@ -27,6 +29,20 @@
27 29 static boolean network_enabled = false;
28 30 static boolean passive_enabled = false;
29 31
32 + /**
33 + * Check if gps is enabled, show a toast when disabled
34 + *
35 + * @param context context (this in Activity / getActivity() in Fragment)
36 + * @return true if gps is enabled
37 + */
38 + public static boolean isGpsEnabled(Context context){
39 + LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
40 + Boolean isGpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
41 + if(isGpsEnabled)
42 + Toast.makeText(context, R.string.enable_gps_toast, Toast.LENGTH_LONG).show();
43 + return isGpsEnabled;
44 + }
45 +
30 46 static LocationListener locationListenerPassive = new LocationListener() {
31 47 public void onLocationChanged(Location location) {
32 48 timer1.cancel();