Source: https://developers.woosmap.com/products/geofencing-sdk/android-sdk/concepts/location-permission/

> For clean Markdown of any page, append `.md` to the page URL.

> For a complete documentation index, see https://developers.woosmap.com/llms.txt

# Android Location permission



To protect user privacy, apps that use location services must request location permissions. Check
the [Android Documentation about building location-aware apps](https://developer.android.com/training/location) for more
details.

## Location on Android

Android Location management provide users with a strong control and transparency over location data usages. Recent
changes introduced dedicated permissions for foreground and background location.

Each permission has a combination of the following characteristics:

- **Category**: Either **foreground location** or **background location**.
- **Accuracy**: Either precise location (`ACCESS_FINE_LOCATION`) or approximate location (`ACCESS_COARSE_LOCATION`).

The Woosmap Geofencing SDK requires both accuracy permissions which are automatically added in the manifest along with
the `INTERNET`, `ACCESS_NETWORK_STATE`, and `RECEIVE_BOOT_COMPLETED`. For Geofencing events capabilities you'll also
need to ask for the `ACCESS_BACKGROUND_LOCATION` permission:

```xml

<manifest>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>
</manifest> 
```

## Request Location Permissions

Permission needs to be granted by the user at runtime. Before trying accessing the users' location from the background,
ensure the user consent for required permission. You can do this by checking the `ACCESS_BACKGROUND_LOCATION`
permission. Here is a sample to request permission:

```java  
private void requestPermissions() {  
     boolean shouldProvideRationale =  
            ActivityCompat.shouldShowRequestPermissionRationale(this,  
                    Manifest.permission.ACCESS_FINE_LOCATION);  
  
    // Provide an additional rationale to the user. This would happen if the user denied the  
    // request previously, but didn't check the "Don't ask again" checkbox.  
    if (shouldProvideRationale) {  
        // Displaying permission rationale to provide additional context.  
        ActivityCompat.requestPermissions(MainActivity.this,  
                new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_BACKGROUND_LOCATION},  
                REQUEST_PERMISSIONS_REQUEST_CODE);  
    } else {  
        // Requesting permission
        ActivityCompat.requestPermissions(MainActivity.this,  
                new String[]{Manifest.permission.ACCESS_FINE_LOCATION,  Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_BACKGROUND_LOCATION},  
                REQUEST_PERMISSIONS_REQUEST_CODE);  
    }  
} 
```
