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.
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.
| Symptom | Layer most likely at fault | First check |
|---|---|---|
Instant crash on a specific action, logcat shows MissingForegroundServiceTypeException | Android 14 type declaration | Dump the crash buffer |
Logcat shows Starting FGS with type camera requires permissions | Type-specific normal / runtime permission | Read manifest and granted permissions |
| Feature fails when triggered from background, works from foreground | while-in-use permission or background start restriction | Reproduce one background start |
Logcat shows ForegroundServiceStartNotAllowedException | Android 12 background FGS start ban | Check launch source and exemptions |
Service starts then gets killed within seconds; log mentions did not then call Service.startForeground() | 5-second timing rule | Check the call after startForegroundService() |
| Background sync runs for hours then stops automatically | Android 15 type quota | dumpsys activity services for timeouts |
| No persistent notification, yet the feature seems to run | Notification channel or POST_NOTIFICATIONS | dumpsys notification |
| Fails only after screen off or device locked | Doze, App Standby bucket, vendor background manager | dumpsys 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 version | API | New constraint | Typical sideload consequence |
|---|---|---|---|
| Android 8 | 26 | Background service limits; startForegroundService() introduced; startForeground() must be called within 5 seconds; notification channels mandatory | Old builds die in background; missing startForeground() call crashes |
| Android 9 | 28 | Normal permission FOREGROUND_SERVICE becomes mandatory | Missing declaration throws SecurityException |
| Android 10 | 29 | android:foregroundServiceType first introduced; location gains "only while in use" | Location services start hitting while-in-use limits |
| Android 11 | 30 | camera and microphone types added; those permissions unavailable from background | Background recording is refused |
| Android 12 | 31 | Apps in background may not call startForegroundService(); throws ForegroundServiceStartNotAllowedException, with exemptions | Scheduled sync and boot-start sideloaded apps break at scale |
| Android 13 | 33 | POST_NOTIFICATIONS runtime permission | Does not block FGS start, but hides the notification and looks like "it never started" |
| Android 14 | 34 | targetSdk ≥ 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, connectedDevice | Repackaged builds with deleted permissions, and unadapted builds, crash as soon as targetSdk rises |
| Android 15 | 35 | mediaProcessing added; dataSync and mediaProcessing get a cumulative 6-hour quota per 24 hours; shortService capped at roughly 3 minutes; types startable from BOOT_COMPLETED narrowed | Long syncs are stopped by the system after hours |
| Android 16 | 36 | dataSync deprecated; systemExempted exemption conditions tightened further | Builds 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 value | Normal permission | Related runtime / while-in-use permission | while-in-use restricted | Typical use |
|---|---|---|---|---|
| camera | FOREGROUND_SERVICE_CAMERA | CAMERA | Yes | Background video, video calls |
| microphone | FOREGROUND_SERVICE_MICROPHONE | RECORD_AUDIO | Yes | Recording, transcription |
| location | FOREGROUND_SERVICE_LOCATION | ACCESS_FINE_LOCATION / ACCESS_COARSE_LOCATION | Yes | Navigation, track logging |
| health | FOREGROUND_SERVICE_HEALTH | BODY_SENSORS, ACTIVITY_RECOGNITION, HIGH_SAMPLING_RATE_SENSORS | Yes | Health monitoring, workouts |
| connectedDevice | FOREGROUND_SERVICE_CONNECTED_DEVICE | BLUETOOTH_CONNECT, BLUETOOTH_SCAN, NEARBY_DEVICES etc. | Partly | Watch/earbud pairing, USB devices |
| dataSync | FOREGROUND_SERVICE_DATA_SYNC | None | No | Upload/download, backup sync (deprecated from API 35) |
| mediaPlayback | FOREGROUND_SERVICE_MEDIA_PLAYBACK | None | No | Music, podcasts |
| mediaProjection | FOREGROUND_SERVICE_MEDIA_PROJECTION | Requires user-consented MediaProjection grant | No | Screen recording, casting |
| mediaProcessing | FOREGROUND_SERVICE_MEDIA_PROCESSING | None | No | Image/video transcoding (API 35+) |
| phoneCall | FOREGROUND_SERVICE_PHONE_CALL | MANAGE_OWN_CALLS or default dialer role | No | VoIP calls |
| remoteMessaging | FOREGROUND_SERVICE_REMOTE_MESSAGING | None | No | Cross-device message sync |
| shortService | None | None | No | Short uninterruptible tasks, roughly 3 minutes |
| specialUse | FOREGROUND_SERVICE_SPECIAL_USE | None, but requires a <property> explaining the use case | No | Legitimate cases outside the categories above |
| systemExempted | FOREGROUND_SERVICE_SYSTEM_EXEMPTED | Requires a system role or explicit exemption | No | System 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 keyword | Trigger | Layer | Fix direction |
|---|---|---|---|
MissingForegroundServiceTypeException | targetSdk ≥ 34 and startForeground() passes no type, or manifest declares no type | Type declaration | Add android:foregroundServiceType and the type argument |
Starting FGS with type xxx requires permissions ... | Missing matching FOREGROUND_SERVICE_<TYPE> or runtime permission | Permission | Add <uses-permission> and grant runtime permission |
SecurityException: Starting a foreground service of type camera requires ... while-in-use | App starts a while-in-use type from background | Start timing | Start while foreground, or use a different type |
ForegroundServiceStartNotAllowedException | Android 12+ background call to startForegroundService() | Background start restriction | Trigger from a user-visible action, or use WorkManager / exact alarm |
ForegroundServiceDidNotStartInTimeException | startForeground() not called within 5 seconds | Timing | Shorten init, call startForeground() first |
RemoteServiceException: Context.startForegroundService() did not then call Service.startForeground() | Same rule, older wording on earlier releases | Timing | Same as above |
IllegalArgumentException: Invalid foreground service type | Type bitmask includes a type not declared in manifest | Type consistency | Align declaration and call site |
Special use FGS ... not allowed | specialUse missing the use-case declaration or review | Special type | Add <property>, or pick another type |
Foreground service ... timed out / time limit exhausted | Android 15 cumulative type quota exhausted | Quota | Move 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.apkSecond, 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.apkThird, 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.xmlIf 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.logReproduce 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.txtEvery <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_SERVICENormal 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.CAMERApm 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 whitelistStep 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.appAdding 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.sdkStep 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.appAcross 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:foregroundServiceTypeandFOREGROUND_SERVICE_<TYPE>, align thestartForeground()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.
| Difference | Play build | Sideloaded build | Consequence |
|---|---|---|---|
| Channel adaptation | targetSdk updated each year | May be an old build stuck at 30/31 | Type checks and background start limits hit different layers |
| Permission declarations | Complete | Repackaged to "trim permissions", dropping FOREGROUND_SERVICE_* | Immediate SecurityException on Android 14 |
| Service declarations | Complete | <service> or type attribute stripped | MissingForegroundServiceTypeException |
| Split install | Split APKs delivered per device | Often only the base APK, missing config splits | Service classes missing or behavior differs |
| Push channel | High-priority FCM exemption available | No GMS means no such exemption | Background start restriction triggers more often |
| Signing and verification | Official signature | Re-signed, installable but treated differently | Some system roles / exemptions lost |
| Background management | Vendors may whitelist well-known apps | Unknown-source apps frozen more aggressively | Silent 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
| Purpose | Command |
|---|---|
| Device API level | adb shell getprop ro.build.version.sdk |
| APK targetSdk | apkanalyzer manifest target-sdk app.apk |
| List declared permissions | apkanalyzer manifest permissions app.apk |
| Read service type declarations | aapt dump xmltree app.apk AndroidManifest.xml |
| Dump crash log | adb logcat -b crash -d |
| Check granted permissions | adb shell dumpsys package com.example.app |
| Check appops | adb shell cmd appops get com.example.app |
| Check FGS state | adb shell dumpsys activity services com.example.app |
| Check standby bucket | adb shell am get-standby-bucket com.example.app |
| Check Doze whitelist | adb shell dumpsys deviceidle whitelist |
| Manually start the service | adb shell am start-foreground-service -n com.example.app/.SyncService |
| Verify the download | curl -sS -o /dev/null -w "%{http_code} %{size_download}\n" -L URL |
| Hash the file | sha256sum 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:
- Android targetSdkVersion Explained: why constraints trigger on targetSdk, not on the OS version
- Android 16 APK Compatibility: broader version-level context
- Autostart and Background App Management: the vendor-side freezing layer
- Restricted Settings and Accessibility for Sideloaded APKs: another post-install restriction
- SCHEDULE_EXACT_ALARM / Exact Alarm Not Firing: the other common background trigger path
- Android 11 Package Visibility and queries: the same "triggered by targetSdk" mechanism class
- Per-App Language Not Following System Locale: another Android 13+ manifest declaration issue
- Default App Role Not Sticking / RoleManager: system roles and exemption eligibility
- Work Profile and Multi-User Install: service differences across users
- App Links Not Opening After Sideload: another "installs but feature broken" case
- Embedded WebView Blank / Cleartext Not Permitted: a targetSdk-driven behavior break
- FileProvider / content URI Share Failure: a manifest-level failure with the same shape
- Scan an APK for Malware Without an Antivirus: confirm whether the build was repackaged or injected
- Sideloaded Game Controller Buttons Not Mapped: another sideload-only functional gap
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.