APK Downloader
·19 min read

Sideloaded APK Background Service Won't Start: Android 14 foregroundServiceType and FGS Type Permissions

You sideload an APK, it installs and opens fine, but the moment you start recording, background sync, navigation, screen casting, or a wearable connection it crashes. The logcat shows MissingForegroundServiceTypeException, Starting FGS with type camera requires permissions, or ForegroundServiceStartNotAllowedException. The APK is not corrupt: Android added six separate layers of restrictions to foreground services between Android 8 and Android 16, and Android 14 made type declarations plus FOREGROUND_SERVICE_* permissions mandatory for targetSdk 34+. This guide gives mechanism tables, copy-paste adb / aapt / apkanalyzer / curl commands, a nine-step diagnostic path, an exception lookup table, version differences, an FAQ, and verified internal links.

foreground serviceforegroundServiceTypeAndroid 14adbtroubleshooting

There is a class of crash that is genuinely confusing. An app installs cleanly, opens normally, and the main UI works perfectly. But the instant you tap "start recording", "sync in background", "begin navigation", "cast screen", or "connect watch", the app crashes — or the feature silently does nothing. Reinstalling, clearing cache, and switching download mirrors change nothing. Only the logs reveal the truth: it is not the UI code failing. The system refused to let a foreground service (FGS) start.

This happens disproportionately often with sideloaded APKs, for three reasons. First, a sideloaded build often declares an older targetSdkVersion than the Play Store build, or has been modified. Second, starting with Android 14 the system strictly validates FGS type declarations and permissions, so deleting a single <uses-permission> line while repackaging is enough to cause a crash. Third, many vendor ROMs add their own background-freezing layer on top of AOSP restrictions, and the two layers together make attribution hard.

This guide follows a fixed order: identify the symptom, understand the mechanism, collect the facts, run a nine-step diagnostic, then decide whether the problem is fixable at all. Every command below runs on a computer with Android SDK platform-tools and build-tools installed. The phone only needs USB debugging enabled. No root required.

1. Narrow it down: which symptoms belong to this class

Not every "background feature stopped working" case is a foreground service being blocked. Use this table first.

SymptomLayer most likely at faultFirst check
Instant crash on a specific action, logcat shows MissingForegroundServiceTypeExceptionAndroid 14 type declarationDump the crash buffer
Logcat shows Starting FGS with type camera requires permissionsType-specific normal / runtime permissionRead manifest and granted permissions
Feature fails when triggered from background, works from foregroundwhile-in-use permission or background start restrictionReproduce one background start
Logcat shows ForegroundServiceStartNotAllowedExceptionAndroid 12 background FGS start banCheck launch source and exemptions
Service starts then gets killed within seconds; log mentions did not then call Service.startForeground()5-second timing ruleCheck the call after startForegroundService()
Background sync runs for hours then stops automaticallyAndroid 15 type quotadumpsys activity services for timeouts
No persistent notification, yet the feature seems to runNotification channel or POST_NOTIFICATIONSdumpsys notification
Fails only after screen off or device lockedDoze, App Standby bucket, vendor background managerdumpsys deviceidle and whitelist

If your symptom is in the first six rows, keep reading. If it is in the last two, jump straight to steps 7, 8, and 9 in section 6.

2. The mechanism: six layers of locks added from Android 8 to Android 16

A foreground service is the legitimate channel for "I need to do something long-running in the background that the user can perceive", paid for with a persistent notification. Starting with Android 8, the platform tightened this channel one release at a time. Each constraint is independent, so diagnosis requires knowing which layer is doing the blocking.

Android versionAPINew constraintTypical sideload consequence
Android 826Background service limits; startForegroundService() introduced; startForeground() must be called within 5 seconds; notification channels mandatoryOld builds die in background; missing startForeground() call crashes
Android 928Normal permission FOREGROUND_SERVICE becomes mandatoryMissing declaration throws SecurityException
Android 1029android:foregroundServiceType first introduced; location gains "only while in use"Location services start hitting while-in-use limits
Android 1130camera and microphone types added; those permissions unavailable from backgroundBackground recording is refused
Android 1231Apps in background may not call startForegroundService(); throws ForegroundServiceStartNotAllowedException, with exemptionsScheduled sync and boot-start sideloaded apps break at scale
Android 1333POST_NOTIFICATIONS runtime permissionDoes not block FGS start, but hides the notification and looks like "it never started"
Android 1434targetSdk ≥ 34 must declare a type per FGS, request matching FOREGROUND_SERVICE_<TYPE> normal permission, and pass a type bitmask to startForeground(); adds health, remoteMessaging, shortService, specialUse, systemExempted, connectedDeviceRepackaged builds with deleted permissions, and unadapted builds, crash as soon as targetSdk rises
Android 1535mediaProcessing added; dataSync and mediaProcessing get a cumulative 6-hour quota per 24 hours; shortService capped at roughly 3 minutes; types startable from BOOT_COMPLETED narrowedLong syncs are stopped by the system after hours
Android 1636dataSync deprecated; systemExempted exemption conditions tightened furtherBuilds relying on legacy types gradually stop working

The decisive boundary is Android 14's `targetSdk ≥ 34`. These constraints trigger on the targetSdkVersion the app itself declares, not on the phone's OS version. An Android 16 phone running a targetSdk 30 build will never hit the API 34 layer; conversely, a targetSdk 34 build on an Android 13 device will not be type-validated either. That is why step 1 must capture *both* the device API level and the APK's targetSdk.

3. Android 14 type list: which permissions each type needs

This is the table people get wrong most often. The system validates three things at once: the <service> node declares android:foregroundServiceType, the manifest requests the matching FOREGROUND_SERVICE_<TYPE> normal permission, and startForeground() passes a type consistent with the declaration. Missing any one of them throws.

Type valueNormal permissionRelated runtime / while-in-use permissionwhile-in-use restrictedTypical use
cameraFOREGROUND_SERVICE_CAMERACAMERAYesBackground video, video calls
microphoneFOREGROUND_SERVICE_MICROPHONERECORD_AUDIOYesRecording, transcription
locationFOREGROUND_SERVICE_LOCATIONACCESS_FINE_LOCATION / ACCESS_COARSE_LOCATIONYesNavigation, track logging
healthFOREGROUND_SERVICE_HEALTHBODY_SENSORS, ACTIVITY_RECOGNITION, HIGH_SAMPLING_RATE_SENSORSYesHealth monitoring, workouts
connectedDeviceFOREGROUND_SERVICE_CONNECTED_DEVICEBLUETOOTH_CONNECT, BLUETOOTH_SCAN, NEARBY_DEVICES etc.PartlyWatch/earbud pairing, USB devices
dataSyncFOREGROUND_SERVICE_DATA_SYNCNoneNoUpload/download, backup sync (deprecated from API 35)
mediaPlaybackFOREGROUND_SERVICE_MEDIA_PLAYBACKNoneNoMusic, podcasts
mediaProjectionFOREGROUND_SERVICE_MEDIA_PROJECTIONRequires user-consented MediaProjection grantNoScreen recording, casting
mediaProcessingFOREGROUND_SERVICE_MEDIA_PROCESSINGNoneNoImage/video transcoding (API 35+)
phoneCallFOREGROUND_SERVICE_PHONE_CALLMANAGE_OWN_CALLS or default dialer roleNoVoIP calls
remoteMessagingFOREGROUND_SERVICE_REMOTE_MESSAGINGNoneNoCross-device message sync
shortServiceNoneNoneNoShort uninterruptible tasks, roughly 3 minutes
specialUseFOREGROUND_SERVICE_SPECIAL_USENone, but requires a <property> explaining the use caseNoLegitimate cases outside the categories above
systemExemptedFOREGROUND_SERVICE_SYSTEM_EXEMPTEDRequires a system role or explicit exemptionNoSystem apps, device owner, VPN

The four while-in-use types (camera, microphone, location, health) carry one extra rule: even with every permission granted, an app in the background cannot hold "only while in use" permissions, so starting one of these FGS types from the background is rejected outright. This is by design, not a bug. To keep recording alive after the screen turns off, the service must be started while the app is still in the foreground.

shortService is frequently misused. It is meant for short tasks that must finish in seconds and cannot be interrupted. When it times out, the system stops the service and the app receives a crash callback. Using it as a general long-running background service is guaranteed to fail.

4. Exception lookup: what that logcat line actually means

Classify the exception first, then choose a direction. This avoids half the wasted effort.

Logcat keywordTriggerLayerFix direction
MissingForegroundServiceTypeExceptiontargetSdk ≥ 34 and startForeground() passes no type, or manifest declares no typeType declarationAdd android:foregroundServiceType and the type argument
Starting FGS with type xxx requires permissions ...Missing matching FOREGROUND_SERVICE_<TYPE> or runtime permissionPermissionAdd <uses-permission> and grant runtime permission
SecurityException: Starting a foreground service of type camera requires ... while-in-useApp starts a while-in-use type from backgroundStart timingStart while foreground, or use a different type
ForegroundServiceStartNotAllowedExceptionAndroid 12+ background call to startForegroundService()Background start restrictionTrigger from a user-visible action, or use WorkManager / exact alarm
ForegroundServiceDidNotStartInTimeExceptionstartForeground() not called within 5 secondsTimingShorten init, call startForeground() first
RemoteServiceException: Context.startForegroundService() did not then call Service.startForeground()Same rule, older wording on earlier releasesTimingSame as above
IllegalArgumentException: Invalid foreground service typeType bitmask includes a type not declared in manifestType consistencyAlign declaration and call site
Special use FGS ... not allowedspecialUse missing the use-case declaration or reviewSpecial typeAdd <property>, or pick another type
Foreground service ... timed out / time limit exhaustedAndroid 15 cumulative type quota exhaustedQuotaMove to WorkManager or split the task

Distinguish "crash" from "silent failure". The first four rows usually surface as an actual crash (exception reaching the main thread or crash buffer); the later rows more often show up as a feature that runs and then stops, or never starts. Dump both log buffers.

5. Before you start: collect four facts about the APK and the device

Run these four groups first and write down the results. Every judgment in the nine steps below depends on them; guessing while changing things only compounds the problem.

First, confirm the device API level and the APK targetSdk, to decide whether the Android 14 layer is active:

adb devices
adb shell getprop ro.build.version.sdk
adb shell getprop ro.build.version.release
aapt dump badging app.apk | grep -E "package:|targetSdkVersion|uses-permission"
apkanalyzer manifest target-sdk app.apk
apkanalyzer manifest permissions app.apk

Second, confirm the APK in your hand is the exact build the download source advertises. Repackaging, CDN caching, and broken resumed-download concatenation all produce "analyzing the official manifest while a different file is actually installed":

curl -sS -I -L "https://example.com/app.apk" | grep -iE "content-length|last-modified|etag|content-type"
curl -sS -o /dev/null -w "%{http_code} %{size_download} %{content_type}\n" -L "https://example.com/app.apk"
sha256sum app.apk

Third, dump the crash and main buffers and find the exception class name:

adb logcat -b crash -d | grep -iE "MissingForegroundServiceType|ForegroundService|SecurityException|startForeground"
adb logcat -v threadtime -d -t 2000 | grep -iE "ActivityManager|ForegroundService|appops|Permission Denial"

Fourth, read the type declarations on the service nodes. aapt reads the binary AndroidManifest directly; apktool gives a more readable decompiled version:

aapt dump xmltree app.apk AndroidManifest.xml | grep -i -A4 -B4 "foregroundServiceType"
apktool d app.apk -o out
grep -n -i -A6 "foregroundServiceType" out/AndroidManifest.xml

If there is no foregroundServiceType anywhere in the output and the targetSdk is 34 or higher, it is almost certain the build was never adapted for Android 14 foreground service types — or that a repackager stripped them. Confirm in step 3 of the next section.

6. Nine-step diagnostic path

Step 1: Confirm which constraints are active

Compare the device API against the APK targetSdk using the table in section 2. Type validation and FOREGROUND_SERVICE_<TYPE> checks fully apply only when targetSdk ≥ 34 and device API ≥ 34. A targetSdk ≤ 33 build on Android 16 will never throw MissingForegroundServiceTypeException, though it can still hit Android 12's background start ban and some Android 15 quota behavior.

Step 2: Capture the exception and pin down the layer

adb logcat -c
adb logcat -b crash,main -v threadtime > fgs.log

Reproduce the failure on the phone once, stop the capture, and match a keyword from the table in section 4. Once you have the exception class, you only need the two or three steps relevant to that layer — there is no need to run all nine.

Step 3: Verify the manifest type declarations

aapt dump xmltree app.apk AndroidManifest.xml > manifest.txt
grep -n -i -E "foregroundServiceType|FOREGROUND_SERVICE|<service" manifest.txt

Every <service> node should carry its own android:foregroundServiceType, and <uses-permission> should include the matching android.permission.FOREGROUND_SERVICE_<TYPE>. A type without its permission, or a permission without its type, both fail. Watch for a classic repackaging mistake: deleting the whole FOREGROUND_SERVICE_* line to "trim permissions" causes an immediate SecurityException on Android 14.

Step 4: Verify the permissions are actually granted

adb shell pm list permissions | grep -i FOREGROUND_SERVICE
adb shell dumpsys package com.example.app | grep -iE -A40 "requested permissions"
adb shell dumpsys package com.example.app | grep -iE "targetSdk|FOREGROUND_SERVICE"
adb shell pm list permissions -g -d | grep -i FOREGROUND_SERVICE

Normal permissions are normally granted at install time, but if they were never declared they will not appear here. Runtime permissions (CAMERA, RECORD_AUDIO, location, and so on) need separate confirmation:

adb shell dumpsys package com.example.app | grep -iE -A20 "runtime permissions"
adb shell cmd appops get com.example.app
adb shell pm grant com.example.app android.permission.CAMERA

pm grant can only grant dangerous permissions already declared in the manifest; it cannot invent one. Use it to test the "permission was not granted" hypothesis, not as a real fix.

Step 5: Decide whether it is a while-in-use timing problem

If the type is camera, microphone, location, or health, and the failure only appears when triggered from the background while foreground triggering works, it is the while-in-use restriction. Reproduce by backgrounding the app and starting the service from a command, then check whether SecurityException or ForegroundServiceStartNotAllowedException appears:

adb shell am start-foreground-service -n com.example.app/.SyncService
adb logcat -b crash -d | grep -iE "SecurityException|ForegroundServiceStartNotAllowed|while-in-use"

There is no user-side fix for this. The app must start the service while still in the foreground, or use a type that does not require while-in-use permissions.

Step 6: Check the background start restriction and exemptions

Since Android 12, calling startForegroundService() from the background is refused. Exemptions include user-visible actions, high-priority FCM, exact alarm callbacks, geofencing, and device owner. Sideloaded apps often lack GMS and therefore lack the FCM exemption, which is why they behave worse than the Play build:

adb shell am get-standby-bucket com.example.app
adb shell dumpsys usagestats | grep -i -A3 "standby"
adb shell dumpsys deviceidle | grep -iE "mEnabled|mState|whitelist"
adb shell dumpsys deviceidle whitelist

Step 7: Check battery optimization and vendor background freezing

Beyond AOSP, most vendor ROMs ship their own background manager. Even a legitimately started FGS can be frozen after the screen turns off:

adb shell dumpsys deviceidle whitelist
adb shell dumpsys deviceidle whitelist +com.example.app
adb shell dumpsys power | grep -iE "mWakefulness|mDeviceIdleMode"
adb shell am set-standby-bucket com.example.app active
adb shell dumpsys activity services com.example.app

Adding the app to the Doze whitelist and turning off battery optimization in Settings are among the few genuinely effective user-side actions. But be clear: they solve "frozen after start", not "blocked at start by type or permission".

Step 8: Check Android 15 type quotas and timeouts

If the service starts fine and stops by itself after a few hours, look at quotas. dataSync and mediaProcessing have a cumulative limit of roughly 6 hours per 24-hour window, and shortService about 3 minutes:

adb shell dumpsys activity services com.example.app
adb shell dumpsys activity services | grep -iE "timeout|time limit|fg service|isForeground"
adb shell getprop ro.build.version.sdk

Step 9: Confirm the notification chain, then conclude

An FGS must be bound to a notification. A disabled channel or missing POST_NOTIFICATIONS grant does not stop the service from starting, but it makes users think "it never started":

adb shell dumpsys notification --noredact | grep -i -A6 "com.example.app"
adb shell cmd notification get_app_config com.example.app

Across the nine steps, sort the conclusion into one of three buckets:

  • Fixable by the user: turn off battery optimization, add to Doze whitelist, grant missing runtime permissions, trigger the feature while the app is in the foreground, adjust the standby bucket.
  • Fixable by swapping the build: install the official Play build, use a version whose targetSdk matches the device, use a clean build whose permission declarations were not modified.
  • Requires a developer fix: add android:foregroundServiceType and FOREGROUND_SERVICE_<TYPE>, align the startForeground() type argument, move to WorkManager or user-visible triggers, migrate long tasks off dataSync. The third bucket cannot be worked around on the user side.

7. Why the sideloaded build behaves differently from the Play build

Same app, same version number, works from the store and crashes when sideloaded — it is not magic. It is usually one of these differences.

DifferencePlay buildSideloaded buildConsequence
Channel adaptationtargetSdk updated each yearMay be an old build stuck at 30/31Type checks and background start limits hit different layers
Permission declarationsCompleteRepackaged to "trim permissions", dropping FOREGROUND_SERVICE_*Immediate SecurityException on Android 14
Service declarationsComplete<service> or type attribute strippedMissingForegroundServiceTypeException
Split installSplit APKs delivered per deviceOften only the base APK, missing config splitsService classes missing or behavior differs
Push channelHigh-priority FCM exemption availableNo GMS means no such exemptionBackground start restriction triggers more often
Signing and verificationOfficial signatureRe-signed, installable but treated differentlySome system roles / exemptions lost
Background managementVendors may whitelist well-known appsUnknown-source apps frozen more aggressivelySilent failure after screen off

This also explains why "download it again" rarely helps: if the mirror itself serves the build with removed permissions, every download yields the same manifest. Base the decision on the hash comparison in section 5 and the manifest read in step 3, not on the number of retries. For the broader verification workflow, see How to Safely Download APK Files on Android: A Full Verification Workflow; if you want a pre-download decision procedure, see Android APK Compatibility Check Before Download. For install-stage errors, see Android APK Install Failed Error Codes.

8. Command quick reference

PurposeCommand
Device API leveladb shell getprop ro.build.version.sdk
APK targetSdkapkanalyzer manifest target-sdk app.apk
List declared permissionsapkanalyzer manifest permissions app.apk
Read service type declarationsaapt dump xmltree app.apk AndroidManifest.xml
Dump crash logadb logcat -b crash -d
Check granted permissionsadb shell dumpsys package com.example.app
Check appopsadb shell cmd appops get com.example.app
Check FGS stateadb shell dumpsys activity services com.example.app
Check standby bucketadb shell am get-standby-bucket com.example.app
Check Doze whitelistadb shell dumpsys deviceidle whitelist
Manually start the serviceadb shell am start-foreground-service -n com.example.app/.SyncService
Verify the downloadcurl -sS -o /dev/null -w "%{http_code} %{size_download}\n" -L URL
Hash the filesha256sum app.apk

Replace com.example.app with the real package name (adb shell pm list packages | grep -i keyword) and .SyncService with the service class name read from the manifest. %{http_code} is literal inside a code block, so copy and paste as-is.

9. FAQ

Q1: Why does only the sideloaded build crash, while the Play build is fine?

The two most common causes are modified permission declarations and a different targetSdkVersion. Walk the comparison table in section 7, focusing on whether every FOREGROUND_SERVICE_* is present and whether targetSdk matches. Hash both APKs with sha256sum; different hashes already prove they are not the same build.

Q2: Is a build with targetSdk below 34 completely unaffected?

It is exempt from Android 14's type and FOREGROUND_SERVICE_<TYPE> checks, but still subject to Android 8's 5-second timing rule, Android 9's FOREGROUND_SERVICE normal permission, Android 12's background start ban, and vendor freezing. "Older is safer" holds only for specific layers.

Q3: Does turning off battery optimization fix it?

Only the "frozen after it started" class. It has zero effect on the three start-time blocks: MissingForegroundServiceTypeException, SecurityException, and ForegroundServiceStartNotAllowedException. To tell them apart, check whether the service ever appeared in dumpsys activity services.

Q4: What does it mean if `adb shell am start-foreground-service` reproduces the error?

It confirms the start path is genuinely blocked by the system. Note that a start issued from adb counts as a background start and easily triggers the Android 12 restriction. It is useful for proving "the restriction is active", but it is not equivalent to the app's normal user-visible trigger — do not treat it as the app's real behavior.

Q5: The manifest already declares a type. Why is there still a `SecurityException`?

Check three things: whether the matching FOREGROUND_SERVICE_<TYPE> is also declared, whether the runtime permission is granted, and whether the type bitmask passed to startForeground() matches the declaration. Any mismatch throws. Also check whether a ROM or repackaging tool post-processed the manifest.

Q6: Can `shortService` be used as a general background task?

No. It times out at roughly 3 minutes, after which the system stops the service and the app gets a crash callback. It is for short tasks that must not be interrupted. For long-running sync, use WorkManager or a resumable, checkpointed task.

Q7: How do I check the Android 15 six-hour quota?

Use adb shell dumpsys activity services <package> to inspect service state and timeout info, and getprop ro.build.version.sdk to confirm the device is API 35+. The quota accumulates over a 24-hour window and applies to both dataSync and mediaProcessing.

Q8: Will a missing notification permission stop the foreground service from starting?

No. POST_NOTIFICATIONS is an Android 13 runtime permission; without it the notification is hidden or the channel collapsed, but the FGS can still start. A fully disabled notification channel, or an app that never calls startForeground() to bind a notification, causes a different timing exception — keep those separate.

Q9: Which cases are completely impossible to work around on the user side?

Missing type/permission declarations, a startForeground() type mismatch, starting a while-in-use type from the background, and an exhausted Android 15 quota. All of these live in app code; only a developer fix or a different, adapted build helps. User-side actions are limited to the first two rows of section 7.

Q10: What exactly should a developer change?

Declare android:foregroundServiceType on every <service>, request the matching FOREGROUND_SERVICE_<TYPE> plus required runtime permissions; pass a type argument to startForeground() consistent with the declaration; move background starts to user-visible actions, WorkManager, or exact alarms; migrate long dataSync tasks to a resumable task model; and add a <property> use-case declaration for specialUse.

10. Further reading

Several articles on this site approach adjacent angles and pair well with this one:

Bottom line

The attribution order is fixed: first confirm the device API and APK targetSdk to determine which layer is active; then use the exception class to identify the layer; then check type declarations, FOREGROUND_SERVICE_* permissions, runtime permissions, and start timing in order; only then consider battery optimization, Doze, and vendor freezing. Users can fix freezing and permission grants. Type declarations, type consistency, and long-task models live in app code and require a different build or a developer fix.

The most practical advice for anyone sideloading: when a background feature crashes on launch, do not reinstall in a panic. Use the four command groups in section 5 to collect the device version, file hash, exception class name, and manifest declarations, then find the difference in the section 7 table. In the vast majority of cases, the answer is already in those four facts.