Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save tshego3/cd050f8fedee2258505f08d83e55bf50 to your computer and use it in GitHub Desktop.

Select an option

Save tshego3/cd050f8fedee2258505f08d83e55bf50 to your computer and use it in GitHub Desktop.
This guide outlines how to handle the "Foreground Service Permission" error in Azure DevOps or Google Play Console, which occurs for apps targeting Android 14 (API level 34) or higher.

Resolving Google Play Foreground Service Permission Errors

1. Understanding the Error

Google requires developers to explicitly declare why their app uses foreground services. If you use a foreground service without an approved declaration in the Play Console, your build will be rejected by the Play Store API (causing the Azure DevOps pipeline to fail).

2. Code Preparation (AndroidManifest.xml)

Before submitting to Google, ensure your code explicitly defines the service type.

  1. Request the specific permission and Declare the service type in the <service> tag:
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android">
        <application android:allowBackup="true" android:icon="@mipmap/appicon" android:supportsRtl="true" android:label="My App">
            <service android:name=".BackgroundService" android:exported="false" android:foregroundServiceType="dataSync" />
        </application>
        <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
        <uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
    </manifest>

3. Creating the Declaration in Google Play Console

Once the code is ready, you must notify Google:

  1. Log in to the Google Play Console.
  2. Go to Policy and programs > App content.
  3. Look for Foreground service permissions and click Start (or Manage).
  4. Select the Type: Choose the type that matches your manifest (e.g., Data sync).
  5. Provide Justification: Explain why the task must run in the background and cannot be done while the app is in the foreground.
  6. Provide a Video Link: Google often requires a video showing the notification that appears when the background service is running.

4. Troubleshooting: "The declaration is missing from App Content"

If you don't see the declaration under App content, it's likely a "chicken-and-egg" problem: Google hasn't seen a build requesting the permission yet, but your automated pipeline can't upload the build because the declaration isn't done.

The Fix:

  1. Generate a Release Build locally (e.g., an .apk file).
  2. Manually upload that file once to the Internal Testing track in the web browser.
  3. The upload might show an error or warning, but it will "trigger" Google to realize your app needs the declaration.
  4. Return to App content; the declaration fields should now be visible.
  5. Complete the declaration and save.
  6. Retry your Azure DevOps pipeline.

Common Foreground Service Types

  • dataSync: For uploading/downloading data.
  • location: For GPS tracking.
  • mediaPlayback: For music/video players.
  • remoteMessaging: For handling messages.

For a full list of types, refer to the Android Developer Documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment