Android Development
Permission Denial
FOREGROUND_SERVICE
Android Permissions
App Error Troubleshooting

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.

Browse interview questions

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:

xml
1<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2    package="com.example.app">
3
4    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
5
6    <application
7        android:allowBackup="true"
8        android:label="@string/app_name">
9
10        <service
11            android:name=".SyncService"
12            android:exported="false" />
13
14    </application>
15</manifest>

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.

kotlin
val intent = Intent(this, SyncService::class.java)
ContextCompat.startForegroundService(this, intent)

And inside the service:

kotlin
1class SyncService : Service() {
2    override fun onCreate() {
3        super.onCreate()
4
5        val notification = NotificationCompat.Builder(this, "sync")
6            .setContentTitle("Sync in progress")
7            .setContentText("Uploading data")
8            .setSmallIcon(R.drawable.ic_stat_name)
9            .build()
10
11        startForeground(1, notification)
12    }
13
14    override fun onBind(intent: Intent?) = null
15}

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.

kotlin
1fun ensureChannel(context: Context) {
2    val manager = context.getSystemService(NotificationManager::class.java)
3    val channel = NotificationChannel(
4        "sync",
5        "Background sync",
6        NotificationManager.IMPORTANCE_LOW
7    )
8    manager.createNotificationChannel(channel)
9}

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:

xml
1<service
2    android:name=".LocationService"
3    android:exported="false"
4    android:foregroundServiceType="location" />

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:

  1. declare android.permission.FOREGROUND_SERVICE
  2. declare the service in the manifest
  3. create the required notification channel
  4. start the service with startForegroundService
  5. call startForeground quickly 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_SERVICE to the manifest.
  • Declare the service and start it with startForegroundService on modern Android.
  • Call startForeground quickly 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 WorkManager instead when the task does not truly need a foreground service.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track 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.

Browse interview questions

All Rights Reserved.