Skip to content

fix(android): allow enableCurrentLocation with only ACCESS_COARSE_LOCATION - #188

Merged
alexgerardojacinto merged 1 commit into
nextfrom
RMET-5644-coarse-location
Nov 16, 2026
Merged

alexgerardojacinto merged 1 commit into
nextfrom
RMET-5644-coarse-location

Conversation

@alexgerardojacinto

@alexgerardojacinto alexgerardojacinto commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Jira: RMET-5644

Problem

The plugin's location permission alias only contained ACCESS_FINE_LOCATION, so on Android:

  • an app declaring only ACCESS_COARSE_LOCATION could never use enableCurrentLocation (rejected with Missing the following permissions in AndroidManifest.xml: android.permission.ACCESS_FINE_LOCATION), and
  • on Android 12+, a user choosing Approximate location in the system dialog got location permission was denied, even in apps that declare both permissions.

Google Maps only needs one of the two permissions to show the current location. This matters because Google Play is making ACCESS_FINE_LOCATION a sensitive permission that requires a Play Console declaration, so apps that don't need precise location should be able to declare only ACCESS_COARSE_LOCATION.

Changes

  • location alias now covers ACCESS_COARSE_LOCATION + ACCESS_FINE_LOCATION, and a new coarseLocation alias covers ACCESS_COARSE_LOCATION (same approach as @capacitor/geolocation).
  • enableCurrentLocation requests the location permissions the app declares in its manifest, and only needs coarse location to be granted to work (precise location also grants coarse):
    • ACCESS_FINE_LOCATION declared: the location alias (coarse + fine) is requested whenever it is not fully granted, even if coarse is already granted. On Android 12+ this shows the "approximate to precise" upgrade prompt, like @capacitor/geolocation. If the user keeps approximate, the call still succeeds with approximate accuracy.
    • Only ACCESS_COARSE_LOCATION declared: only coarse is requested.
    • Neither declared: enableCurrentLocation rejects immediately with a clear message.
  • README (Android): ACCESS_FINE_LOCATION is now optional, ACCESS_COARSE_LOCATION is enough to show the current location, the request behaviour above is described, and the Google Play policy for sensitive location permissions is documented.

The plugin's own AndroidManifest.xml is unchanged: apps keep declaring the location permissions they need.

Behaviour change

For apps that declare ACCESS_FINE_LOCATION, users who pick Approximate no longer get location permission was denied: the call now succeeds with approximate accuracy (previously the call only worked after the user upgraded to precise on a later call). Users who pick Precise are unaffected.

Testing

Manual tests with the example app (Config Maps > Show current location), all on clean installs. No Maps API key was set, so map tiles were blank; the my-location button and results were checked.

Device Android Manifest User action Before (unmodified next) After
Pixel 7 17 none – Rejects ("Missing ... FINE") Rejects with clear message, no crash
Pixel 7 17 coarse only accept Fails Works (only the approximate prompt, fine never requested)
Pixel 7 17 fine + coarse Approximate, then "Keep approximate" on the upgrade prompt Fails ("permission was denied") Works (approximate)
Pixel 7 17 fine + coarse Approximate, then "Change to precise" Works after the upgrade prompt on a later call Works (fine + coarse granted)
Pixel 7 17 fine only Precise – Works
Emulator (Pixel 4) 11 none – Rejects ("Missing ... FINE") Rejects with clear message, no crash
Emulator (Pixel 4) 11 coarse only accept Fails Works
Emulator (Pixel 4) 11 fine + coarse accept Works Works (no regression)
Emulator (Pixel 4) 11 fine only accept – Works

Also: ./gradlew clean build test (includes Android lint), eslint, prettier --check, SwiftLint (pre-commit) all pass.

Notes

  • Android 11 has no approximate/precise choice, so the Approximate case doesn't exist there. Android < 12 was tested on an emulator only.
  • Not covered: Android 17 button-based location flow (out of scope, tracked separately).

Comment on lines +833 to +858
if (hasLocationPermission()) {
internalEnableCurrentLocation(call)
return
}

val coarseDeclared =
PermissionHelper.hasDefinedPermission(
context,
Manifest.permission.ACCESS_COARSE_LOCATION
)
val fineDeclared =
PermissionHelper.hasDefinedPermission(
context,
Manifest.permission.ACCESS_FINE_LOCATION
)

if (!coarseDeclared && !fineDeclared) {
call.reject(
"location permission was denied: neither ACCESS_COARSE_LOCATION nor ACCESS_FINE_LOCATION is declared in the AndroidManifest.xml"
)
return
}

// Only request ACCESS_FINE_LOCATION if the app declared it, otherwise request coarse only.
val alias = if (fineDeclared) LOCATION else COARSE_LOCATION
requestPermissionForAlias(alias, call, "enableCurrentLocationCallback")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the behavior change you mention, here's my opinion, but not that of a strong one:

If the FINE location is defined in manifest, we should request it, even if COARSE is already granted. This would make it similar to geolocation plugin. It requests the permissions defined in the manifest, but only requires COARSE granted to work.

Your comment

Android's guidance is that apps "should still work when the user grants only approximate location" and should ask for precise only if a feature "absolutely requires" it. The my-location dot does not.

While I understand it, that sounds like we're making a decision for the app developer.

Or if we want to allow configuring it, we could have an enableHighAccuracy, but I don't think it's needed.

Furthermore, having this behavior change should maybe be marked as a breaking change for the plugin (even if not a huge one), which is okay, but seems unnecessary to me.

It's just my opinion, if you feel strongly with the current approach, I'm not opposed to it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong opinion about this and what you said makes a lot of sense, even more when considering that's the approach we took for the Geolocation plugin.

I'll make that change now, thank you!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OS-pedrogustavobilro I updated it, can you check again?

…ATION

The `location` permission alias only contained ACCESS_FINE_LOCATION, so
`enableCurrentLocation` was rejected when an app declared only
ACCESS_COARSE_LOCATION, and when the user chose approximate location on
Android 12+, even though Google Maps only needs one of the two.

- `location` alias now covers ACCESS_COARSE_LOCATION and
  ACCESS_FINE_LOCATION, and a new `coarseLocation` alias covers
  ACCESS_COARSE_LOCATION (same approach as the Geolocation plugin)
- the current location is enabled when coarse location is granted
  (precise location also grants coarse)
- ACCESS_FINE_LOCATION is only requested when the app declares it
- reject with a clear message if the app declares neither permission
- README: ACCESS_FINE_LOCATION is now optional; document the Google Play
  policy for sensitive location permissions

This lets apps that don't need precise location avoid declaring
ACCESS_FINE_LOCATION (and the Play Console declaration it requires).

Refs: RMET-5644

@OS-pedrogustavobilro OS-pedrogustavobilro left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested here, it's working well. Leaving a non-blocking comment.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no breaking changes here, so this could technically go in main branch.

But because the main goal here is for Google Play policies that are only in effect for API level 37 (Capacitor 9), I don't mind this staying in next.

@alexgerardojacinto alexgerardojacinto Nov 16, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

main goal here is for Google Play policies that are only in effect for API level 37 (Capacitor 9)

Yeah that was my reasoning. I'll keep it in next and if anything if we for some reason want it in main (or Capacitor 8 once it's in 8.x) in the future we can always cherry pick

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good!

@alexgerardojacinto
alexgerardojacinto merged commit 8f4d8fc into next Nov 16, 2026
10 checks passed
@alexgerardojacinto
alexgerardojacinto deleted the RMET-5644-coarse-location branch November 16, 2026 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants