Skip to content

Commit

Permalink
Permission check should be done before requesting location updates
Browse files Browse the repository at this point in the history
  • Loading branch information
avianey authored Feb 13, 2020
1 parent bfefb04 commit afbe3ca
Showing 1 changed file with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit afbe3ca

Please sign in to comment.