Permission Denial startForeground requires android.permission.FOREGROUND_SERVICE
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
This error appears when an app calls startForeground or starts a foreground service without declaring the required manifest permission. On modern Android, foreground services are tightly controlled because they keep work alive in a user-visible way. The fix is usually simple, but there are a few version-specific requirements that are easy to miss.
Add the Foreground Service Permission to the Manifest
At minimum, declare the permission in AndroidManifest.xml:
Without that uses-permission entry, Android can throw Permission Denial: startForeground requires android.permission.FOREGROUND_SERVICE.
Start the Service the Modern Way
From Android 8.0 onward, you should use startForegroundService when launching a service that will become foreground shortly afterward. Then call startForeground inside the service quickly, usually in onCreate or onStartCommand.
And inside the service:
If you start the service but do not call startForeground soon enough, Android can stop the service even if the manifest permission is present.
Create the Notification Channel on Android 8.0 and Later
Foreground services require an ongoing notification. On Android 8.0 and later, that notification must use a valid channel.
If the notification setup is broken, the service may fail for reasons that look similar to permission issues, so it is worth validating the entire startup path.
Android 14 and Foreground Service Types
On recent Android versions, declaring the base permission is sometimes not enough. If your service performs a specific category of work, you may also need to declare a foreground service type and, depending on the type, extra permissions.
Example:
For location work, you still need the relevant location permissions. For media playback, camera use, health tracking, and other categories, the exact requirements differ. If the app targets newer SDK levels, review foreground service type requirements as part of the fix rather than only adding the base permission.
A Minimal Working Sequence
A reliable startup sequence looks like this:
- declare
android.permission.FOREGROUND_SERVICE - declare the service in the manifest
- create the required notification channel
- start the service with
startForegroundService - call
startForegroundquickly with a valid notification
That sequence resolves most cases of this error.
When You Do Not Need a Foreground Service
Not every background task should be a foreground service. If the work is deferrable, WorkManager is often a better fit. Using a foreground service for short, non-user-visible work increases complexity and can trigger additional platform restrictions on newer Android versions.
Choose a foreground service only when the work is user-visible and truly needs to continue immediately.
Common Pitfalls
The most common mistake is forgetting the android.permission.FOREGROUND_SERVICE manifest entry. Another is starting a service in the background and calling startForeground too late. Developers also forget to create a notification channel on Android 8.0 and later, or they omit android:foregroundServiceType on newer target SDKs when the service category requires it. Finally, some tasks are better modeled with WorkManager, so trying to force everything through a foreground service can create avoidable platform friction.
Summary
- Add
android.permission.FOREGROUND_SERVICEto the manifest. - Declare the service and start it with
startForegroundServiceon modern Android. - Call
startForegroundquickly with a valid notification. - Create the notification channel before building the foreground notification.
- On newer Android versions, review foreground service types and related permissions.
- Use
WorkManagerinstead when the task does not truly need a foreground service.
Related reading
- Picasso v/s Imageloader v/s Fresco vs Glide vs Coil
- Place cursor at the end of text in EditText
- Place cursor at the end of text in EditText
- Placeholder in UITextView
- Permission denied on accessing host directory in Docker
- Permission denied (publickey) when deploying heroku code. fatal The remote end hung up unexpectedly
- Placing/Overlappingz-index a view above another view in android
- Plain Style unsupported in a Navigation Item warning with my customized Bar Button Item
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.