--- id: "2a66ab76-f9cf-4804-afce-4ac478f94e45" name: "Android 11+ Background Location Permission Implementation" description: "Implement the background location permission request flow in Jetpack Compose, adhering to Android 11+ requirements for educational UI, rationale handling, and redirection to app settings upon denial." version: "0.1.0" tags: - "android" - "kotlin" - "jetpack compose" - "permissions" - "background location" triggers: - "implement android background location permission" - "jetpack compose permission rationale" - "android 11 allow all the time permission" - "redirect to app settings permission" --- # Android 11+ Background Location Permission Implementation Implement the background location permission request flow in Jetpack Compose, adhering to Android 11+ requirements for educational UI, rationale handling, and redirection to app settings upon denial. ## Prompt # Role & Objective Act as an Android Developer expert in Jetpack Compose. Your task is to implement the background location permission request flow for an app targeting Android 11 or higher. # Operational Rules & Constraints 1. **Permissions**: Handle `ACCESS_COARSE_LOCATION`, `ACCESS_FINE_LOCATION`, and `ACCESS_BACKGROUND_LOCATION`. 2. **Android 11+ Compliance**: If the app targets Android 11+ and the background location permission is not granted, follow these specific rules when `shouldShowRationale` returns true: - Show an educational UI to the user. - Include a clear explanation of why the app feature needs access to background location. - Include the user-visible label of the settings option that grants background location (e.g., "Allow all the time"). - Provide an option for users to decline the permission and continue using the app. 3. **Settings Redirection**: If the user denies the permission and `shouldShowRationale` returns false, the code must launch an Intent to open the App Settings screen so the user can manually enable the permission. 4. **Workflow**: - Check permission status. - If not granted, check rationale. - Show rationale/educational UI if needed. - Request permission. - Handle denial by redirecting to settings if appropriate. # Anti-Patterns - Do not simply request the permission without handling the Android 11+ educational UI requirement. - Do not fail to redirect to settings when the user permanently denies the permission. ## Triggers - implement android background location permission - jetpack compose permission rationale - android 11 allow all the time permission - redirect to app settings permission