# Background Location Permission

### Background Location Access for Android 10+

Android 10 and later introduce stricter privacy controls, limiting background location access. This guide explains required permissions, Google’s changes, and how Netmera helps request background location access.

{% hint style="warning" %}

#### **Required Permission: ACCESS\_BACKGROUND\_LOCATION**

To access location in the background, your application must request the `ACCESS_BACKGROUND_LOCATION` permission.
{% endhint %}

### Google’s Privacy Changes

* **Privacy Enhancements**: Apps can’t request background location permission directly. Users initially see only “Allow only while using the app” or “Deny.”
* **User Control**: To enable background location, users must manually update settings:\
  **Settings > Apps > \[Your App] > Permissions > Location > Allow always**

### How Netmera Helps

Netmera provides tools to request background location access smoothly.

#### Background Location Permission Event

**What It Does**: Triggers when the app requests `ACCESS_BACKGROUND_LOCATION`.\
**How It Works**: This event can start an automation guiding users to enable background location.

### Setting Up a Background Location Permission Widget

This feature enables Netmera customers to display a widget that informs users about background location permissions. Here’s how to set it up:

### Step 1: Create a Mobile Widget

Use the panel to create a widget that informs users about the need for background location access. Further information can be found on our User Documentation about how to create [**Widgets**](https://user.netmera.com/netmera-user-guide/mobile-widget/mobile-widget-in-app) and [**Adding Click Actions**](https://user.netmera.com/netmera-user-guide/mobile-widget/mobile-widget-in-app/create-new-mobile-widget/click-actions#android-background-location-permission)[**.**](https://user.netmera.com/netmera-user-guide/messages/automated-push-scenarios#handle-special-user-action)

1. **Design Your Widget**
2. **Configure Button Actions**

Set up two button actions:

* **Allow Permission** button: Directs users to **Settings > Location** so they can enable **“Allow always”**.
* **Deny Permission** button: Provides the option to decline.

<figure><img src="https://2578508252-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0bOAscrXzPSujyzq8DEz%2Fuploads%2F6lMszNMOPb4jOuL6Fb7u%2Fimage.png?alt=media&#x26;token=ea7adb47-a80c-47d2-b969-e9b529ffcc4f" alt=""><figcaption></figcaption></figure>

### Step 2: Configure the Permission Event

* Add `ACCESS_BACKGROUND_LOCATION` to your app’s code.
* This triggers the event, launching automation.

### Step 3: Automate a Push Notification

* Send a notification when the event triggers.
* Use **Handle Special Action** to prompt users.

Further information can be found on our User Documentation about Automation Scenarios and [**Handle Special Action**](https://user.netmera.com/netmera-user-guide/messages/automated-push-scenarios#handle-special-user-action).

<figure><img src="https://2578508252-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0bOAscrXzPSujyzq8DEz%2Fuploads%2FnudktcxDXUSGf9ydEEg6%2Fimage.png?alt=media&#x26;token=47d9c709-fd3e-4a64-8a1a-a880816b3066" alt=""><figcaption></figcaption></figure>

### Example Scenario for Automation Setup

1. **Automation Setup:**
   * Begin by setting up the automation in Create New Automation section.
   * Select the **Handle Special Action** tab during the automation configuration.
2. **Event Selection:**
   * In the **Event** section, choose the **Background Location Permission** event. This event is triggered when the background location permission is requested by the SDK.
3. **Occurrence Selection:**
   * Under **Occurrence**, select **1**. This ensures that the event is triggered once, upon the first request for background location permission.
4. **User Limit:**

   * When the **Background Location Permission** is requested, the SDK will trigger the **Background Location Permission event**.
   * It’s important to set a **limit** for how often the widget (asking for permission) is shown to the user. This will prevent showing the widget too frequently and ensure the user experience remains positive.

   **Example of widget frequency limit**: Set the widget to appear no more than **once per week** or based on other suitable time intervals to avoid overuse.

<figure><img src="https://2578508252-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0bOAscrXzPSujyzq8DEz%2Fuploads%2FySvn4EdvygVWwUy4brnb%2Fimage.png?alt=media&#x26;token=f3bbbaaf-a754-4a97-9d55-bc91300c9a55" alt=""><figcaption></figcaption></figure>

### Step 4: Users Updating Settings

When users tap the **Update Setting** button, the SDK redirects them to the device's settings to enable location access.

{% hint style="success" %}
**Background Location Permission** **Event Trigger Conditions**

The event will trigger when **all of the following** are true:

* The device is running Android 10 or above,
* The app includes background location permission in the manifest,
* The app already has foreground location permission.

If both foreground and background permissions are granted, this event will not trigger.
{% endhint %}
