Check if GPS was disabled

This commit is contained in:
jannis 2019-08-25 12:58:43 +02:00
parent 6369e1a434
commit 744f4389d6
2 changed files with 25 additions and 0 deletions

View File

@ -21,9 +21,12 @@ package de.tadris.fitness.activity;
import android.Manifest; import android.Manifest;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.location.Location; import android.location.Location;
import android.location.LocationManager;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
@ -241,6 +244,24 @@ public class RecordWorkoutActivity extends FitoTrackActivity implements Location
}else{ }else{
startService(locationListener); startService(locationListener);
} }
checkGpsStatus();
}
private void checkGpsStatus(){
final LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)){
openDialogNoGps();
}
}
private void openDialogNoGps(){
new AlertDialog.Builder(this)
.setTitle(R.string.noGpsTitle)
.setMessage(R.string.noGpsMessage)
.setNegativeButton(R.string.cancel, (dialog, which) -> finish())
.setPositiveButton(R.string.enable, (dialog, which) -> startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS)))
.create().show();
} }
@Override @Override

View File

@ -72,6 +72,10 @@
<string name="recordWorkout">Record Workout</string> <string name="recordWorkout">Record Workout</string>
<string name="noGpsTitle">GPS disabled</string>
<string name="noGpsMessage">Please enable GPS for tracking your workout.</string>
<string name="enable">Enable</string>
<string name="comment">Comment</string> <string name="comment">Comment</string>
<string name="enterComment">Enter Comment</string> <string name="enterComment">Enter Comment</string>
<string name="okay">Okay</string> <string name="okay">Okay</string>