Question

Android WorkManager without it's foreground service

How are you supposed to setup Android WorkManager, if you would just like to only use it's background service?

USE-CASE: have a PeriodicWorker scheduled to run every 30M, which performs data sync with server, when app is on foreground. Data sync will be < 12 minutes, which seems to be Googles definition for long-running task. Worker won't be calling setForegroundInfo() which hints Android WorkManager that it should be executed in background service.

Problem is that WorkManager includes FOREGROUND_SERVICE permission, when manifest is merged, and that then will let Google Play believe app is using foreground services. Which then leads is submission rejection, due targetSdk 34 requirements.

FOREGROUND_SERVICE permission (and androidx.work.impl.foreground.SystemForegroundService) can be removed using tools:node="remove" from manifest, but is this proper way of telling Google that you'll only need to use background service of WorkManager?

 2  53  2
1 Jan 1970

Solution

 0

I have a similar issue. I use WorkManager to schedule a local push notification and don't use foreground services at all. I added these entries to the manifest to let them know.

        <service
            android:name="androidx.work.impl.foreground.SystemForegroundService"
            android:foregroundServiceType="specialUse"
            tools:node="merge">
            <property android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
                android:value="The app itself doesn't use foreground services. The Work Manager library’s manifest includes this foreground service entry, specialUse type specified to meet the requirements for Android 14."/>
        </service>
2024-07-22
HaDenG