Fix permissions

This commit is contained in:
Mieszko Wrzeszczyński 2018-11-05 10:04:32 +01:00
parent 8ca2f7dc31
commit 03c38a8f23
3 changed files with 10 additions and 22 deletions

View File

@ -57,8 +57,6 @@ public abstract class BaseActivity
private ActionBarDrawerToggle actionBarDrawerToggle; private ActionBarDrawerToggle actionBarDrawerToggle;
private SharingFragment sharingFragment; private SharingFragment sharingFragment;
boolean boolean_permission;
private Fragment userListFragment; private Fragment userListFragment;
private ActiveFragment activeFragment = ActiveFragment.NONE; private ActiveFragment activeFragment = ActiveFragment.NONE;
@ -111,12 +109,12 @@ public abstract class BaseActivity
sharingFragment = new SharingFragment(); sharingFragment = new SharingFragment();
userListFragment = new UsersListFragment(); userListFragment = new UsersListFragment();
isTutor = PrefUtils.getIsTutor(getApplicationContext()); isTutor = PrefUtils.getIsTutor(getApplicationContext());
if (!isTutor) { if (!isTutor) {
navigationView.findViewById(R.id.nav_profile).setVisibility(View.GONE); navigationView.findViewById(R.id.nav_profile).setVisibility(View.GONE);
} }
checkPermissions();
} }
@ -168,25 +166,14 @@ public abstract class BaseActivity
} }
public void startBackgroundLocalizationTask() { public void startBackgroundLocalizationTask() {
if ((ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED)) { checkPermissions();
if ((ActivityCompat.shouldShowRequestPermissionRationale(this, android.Manifest.permission.ACCESS_FINE_LOCATION))) { Intent startIntent = new Intent(getApplicationContext(), BackgroundLocalizationService.class);
} else { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION startForegroundService(startIntent);
},
REQUEST_PERMISSIONS);
}
} else { } else {
startService(startIntent);
Intent startIntent = new Intent(getApplicationContext(), BackgroundLocalizationService.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForegroundService(startIntent);
} else {
startService(startIntent);
}
} }
} }

View File

@ -109,7 +109,6 @@ public class MapActivity extends BaseActivity
coordinateService = ApiClient.getClient(getApplicationContext()) coordinateService = ApiClient.getClient(getApplicationContext())
.create(CoordinateService.class); .create(CoordinateService.class);
//
mStatusChecker = () -> { mStatusChecker = () -> {
try { try {
fetchTopCoords(); fetchTopCoords();
@ -466,7 +465,6 @@ public class MapActivity extends BaseActivity
locationComponent.setCameraMode(CameraMode.TRACKING); locationComponent.setCameraMode(CameraMode.TRACKING);
locationComponent.setRenderMode(RenderMode.COMPASS); locationComponent.setRenderMode(RenderMode.COMPASS);
// Button 4 centring // Button 4 centring
FloatingActionButton myLocFAB = findViewById(R.id.myLocationButton); FloatingActionButton myLocFAB = findViewById(R.id.myLocationButton);
myLocFAB.setOnClickListener(v -> { myLocFAB.setOnClickListener(v -> {

View File

@ -25,6 +25,7 @@ public class RestApiHelper extends Activity {
} catch (Exception e) { } catch (Exception e) {
return e.getMessage(); return e.getMessage();
} }
} }
@ -34,6 +35,8 @@ public class RestApiHelper extends Activity {
if (e instanceof HttpException) { if (e instanceof HttpException) {
ResponseBody responseBody = ((HttpException) e).response().errorBody(); ResponseBody responseBody = ((HttpException) e).response().errorBody();
message = RestApiHelper.getErrorMessage(responseBody); message = RestApiHelper.getErrorMessage(responseBody);
} else {
message ="Network Error !";
} }
Snackbar snackbar = Snackbar.make(findViewById(R.id.activity_content), message, Snackbar.LENGTH_LONG); Snackbar snackbar = Snackbar.make(findViewById(R.id.activity_content), message, Snackbar.LENGTH_LONG);