Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permission check should be done before requesting location updates #278

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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