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).
Before submitting to Google, ensure your code explicitly defines the service type.
- 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>
Once the code is ready, you must notify Google:
- Log in to the Google Play Console.
- Go to Policy and programs > App content.
- Look for Foreground service permissions and click Start (or Manage).
- Select the Type: Choose the type that matches your manifest (e.g.,
Data sync). - Provide Justification: Explain why the task must run in the background and cannot be done while the app is in the foreground.
- Provide a Video Link: Google often requires a video showing the notification that appears when the background service is running.
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:
- Generate a Release Build locally (e.g., an
.apkfile). - Manually upload that file once to the Internal Testing track in the web browser.
- The upload might show an error or warning, but it will "trigger" Google to realize your app needs the declaration.
- Return to App content; the declaration fields should now be visible.
- Complete the declaration and save.
- Retry your Azure DevOps pipeline.
- 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.