skip to content

On Android, how should a nearby-posts feature declare and request location permissions, and what must it handle when the user grants only approximate location?

level: middleimportance: should knowfreq 60%

answer

  1. coarse always, fine only if needed
  2. the user picks the accuracy
  3. background is its own permission
  4. a session-only button in Android 17

basics

~20 s

Declare ACCESS_COARSE_LOCATION, and ACCESS_FINE_LOCATION only if precision truly helps, then request them together at the moment the feature opens. If the user grants approximate only, the app gets approximate locations whatever it declared, so the feature must work on them.

solid answer

~50 s

Location permissions vary on two axes: foreground or background, and approximate or precise. For nearby posts I declare `ACCESS_COARSE_LOCATION`, which the docs say to always include, and add `ACCESS_FINE_LOCATION` only if the feature genuinely benefits from precision; nearby posts usually don't. I request them together with `RequestMultiplePermissions` when the user opens the nearby tab. The user can still grant only approximate access, and then the app receives approximate locations (within about 3 square kilometres from the fused provider) regardless of what it declared, so the ranking must work at that resolution. Background access is separate: on Android 10 (API 29) and higher it needs `ACCESS_BACKGROUND_LOCATION` declared, and Play restricts it to core features. For a one-off 'search near me', Android 17 (API 37) adds a system location button that grants precise location for the session without a dialog.

code

kotlin · 27 lines
kotlin
import android.Manifest
import androidx.activity.ComponentActivity
import androidx.activity.result.contract.ActivityResultContracts

class NearbyPostsActivity : ComponentActivity() {

    private val locationPermissions =
        registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { result ->
            when {
                result[Manifest.permission.ACCESS_FINE_LOCATION] == true -> loadNearby(precise = true)
                result[Manifest.permission.ACCESS_COARSE_LOCATION] == true -> loadNearby(precise = false)
                else -> showCityPicker()
            }
        }

    fun onNearbyTabOpened() {
        locationPermissions.launch(
            arrayOf(
                Manifest.permission.ACCESS_COARSE_LOCATION,
                Manifest.permission.ACCESS_FINE_LOCATION,
            )
        )
    }

    private fun loadNearby(precise: Boolean) { /* widen the radius when !precise */ }
    private fun showCityPicker() { /* manual fallback: the user types a city */ }
}

go deeper

for a junior

Recall the three location permissions and that coarse is the one to always declare, with fine added only when precision matters.

for a middle

Explain how a request for both can end in approximate-only, why the app must read each result separately, and why background location is its own permission.

for a senior

Show the degraded paths in practice: a wider radius, a typed-city fallback, and spotting a dependency that slipped precise location into the merged manifest.

for a principal

Weigh accuracy against trust: a lead defaults to approximate or session-only location and makes any feature that wants precision argue for it.

## Two axes, several permissions Android's location permissions combine two characteristics: - **Category**: *foreground* location (an activity of the app is visible, or the app runs a foreground service) or *background* location (any other situation). - **Accuracy**: *approximate* or *precise*. The permissions map onto those axes: | Permission | What it unlocks | Notes | |---|---|---| | `ACCESS_COARSE_LOCATION` | Approximate location; from the platform or fused location provider, accurate to within about 3 square kilometres | The documentation says to include it any time the app needs location | | `ACCESS_FINE_LOCATION` | Precise location, usually within about 50 metres | Include only if the app benefits from precision | | `ACCESS_BACKGROUND_LOCATION` | Access outside the foreground situations | Required on Android 10 (API 29) and higher to request background access at runtime | All three are runtime (dangerous) permissions: declared with `<uses-permission>`, then requested. The accuracy gap is large. Precise location from the platform or fused provider is usually within about 50 metres and sometimes within a few metres; approximate is an area of about 3 square kilometres. That is the right resolution for "posts in your part of town" and the wrong one for "the café you are standing in", which is why the choice of permission should follow the feature, not habit. ## Declaring for "nearby posts" A social app's nearby feed needs to know roughly where the user is. Android's guidance on minimising permissions is direct: request coarse location when precision is unnecessary, and declare `ACCESS_FINE_LOCATION` only in the situations that need a precise estimate. A feed sorted by distance at neighbourhood scale works on approximate location, so the cleanest manifest is: ```xml <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> ``` If a later feature (say, tagging an exact venue) needs precision, you add `ACCESS_FINE_LOCATION` and request both together with `RequestMultiplePermissions` when that feature opens, handling the result for each permission separately. ## When the user grants only approximate Even when the app asks for precise location, the user may grant only approximate access, or refuse entirely. The documentation states the consequence plainly: if the user grants the approximate permission, the app **only has access to approximate location, regardless of which location permissions it declares**. So: 1. Read the result per permission: coarse granted and fine denied is a normal, supported outcome. 2. Make the feature work at approximate accuracy. For nearby posts that means a coarser radius and perhaps a label such as "near you" instead of an exact distance, not an error screen. 3. If one feature *absolutely* requires precision, ask for precise access in that feature's context, explaining why, and keep the approximate path working if the user says no. ## Background location is a separate decision Before Android 10, foreground access implied background access. On Android 10 (API 29) and higher, the app must declare **`ACCESS_BACKGROUND_LOCATION`** to request background access at runtime, and the first background access after the grant makes the system notify the user that the app may use location all the time. Google Play's location policy restricts background access to apps that need it for core functionality. A nearby feed that refreshes while the app is open has no case for it. ## One-time and session-only access Two mechanisms shrink the grant further: - **"Only this time"** (Android 11 / API 30): the dialog for location, microphone or camera offers a one-time grant that lasts while the app is in use and lapses afterwards. Code that checks before every access handles it without changes. - **The system location button** (Android 17 / API 37): a system-rendered button, embedded through Jetpack, that grants **precise location for the current session only, without a permission dialog**. It requires the `USE_LOCATION_BUTTON` permission. If an app targets API 37 or higher and its features only need session-based location, Google Play policy requires the location button. For a "posts near me right now" search, the button can replace the dialog altogether. ## A checklist for the nearby feature - Declare coarse; add fine only for a feature that needs it. - Request at the moment the user opens the nearby tab, not at launch. - Treat approximate-only as a success case. - Never request background location for a foreground feed. - Offer a manual fallback (a typed city or postal code) when location is denied; the guidance suggests it for apps that need location rarely. - Remember that a library can add `ACCESS_FINE_LOCATION` to your merged manifest; check your dependencies.

  • Why does declaring ACCESS_FINE_LOCATION not guarantee precise locations?
    Because the user chooses the accuracy. If they grant only approximate access, the app receives approximate locations regardless of the permissions in its manifest. The app has to read the result for each permission and keep the feature working at the coarser accuracy, asking for precise access only where a feature cannot work without it.
  • When should an app use Android 17's location button instead of a permission request?
    When a feature needs location only at a specific moment, such as 'search near me' or filling an address. Tapping the system-rendered button grants precise location for the current session without a dialog; the app declares `USE_LOCATION_BUTTON`. For apps that target API 37 and only need session-based access, Google Play policy requires the button.

  • Declaring ACCESS_FINE_LOCATION guarantees the app precise location once granted.
  • Foreground location permission also covers background access on current Android versions.
  • A nearby feed should request ACCESS_BACKGROUND_LOCATION to stay fresh.
  • Approximate-only is a failure the app should treat as a denial.

Assumes Android 17 (API 37): background location needs its own permission since Android 10 (API 29), one-time grants exist since Android 11 (API 30), and the location button arrives with API 37.