From afbe3ca73f2d8618d50faccde250ea77e70e30d5 Mon Sep 17 00:00:00 2001 From: Antoine Vianey Date: Thu, 13 Feb 2020 10:16:41 +0100 Subject: [PATCH] Permission check should be done before requesting location updates #277 --- .../providers/LocationManagerProvider.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/library/src/main/java/io/nlopez/smartlocation/location/providers/LocationManagerProvider.java b/library/src/main/java/io/nlopez/smartlocation/location/providers/LocationManagerProvider.java index 75567a5a..fbef7a9a 100644 --- a/library/src/main/java/io/nlopez/smartlocation/location/providers/LocationManagerProvider.java +++ b/library/src/main/java/io/nlopez/smartlocation/location/providers/LocationManagerProvider.java @@ -48,18 +48,19 @@ public void start(OnLocationUpdatedListener listener, LocationParams params, boo Criteria criteria = getProvider(params); - if (singleUpdate) { - if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION) - != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(mContext, - Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { - logger.i("Permission check failed. Please handle it in your app before setting up location"); - // TODO: Consider calling ActivityCompat#requestPermissions here to request the - // missing permissions, and then overriding onRequestPermissionsResult - // to handle the case where the user grants the permission. See the documentation - // for ActivityCompat#requestPermissions for more details. + if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION) + != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(mContext, + Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { + logger.i("Permission check failed. Please handle it in your app before setting up location"); + // TODO: Consider calling ActivityCompat#requestPermissions here to request the + // missing permissions, and then overriding onRequestPermissionsResult + // to handle the case where the user grants the permission. See the documentation + // for ActivityCompat#requestPermissions for more details. - return; - } + return; + } + + if (singleUpdate) { locationManager.requestSingleUpdate(criteria, this, Looper.getMainLooper()); } else { locationManager.requestLocationUpdates(