Mudanças nos serviços em primeiro plano
Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
A documentação sobre serviços em primeiro plano descreve o comportamento atual dos
serviços em primeiro plano do Android. A documentação oferece orientações sobre as práticas recomendadas para a maioria dos apps, com ou sem segmentação para a versão mais recente do Android.
Esta página descreve algumas das mudanças importantes mais recentes nos serviços
em primeiro plano e as implicações para apps que não têm como destino a versão mais
recente da plataforma Android. Em muitos casos, as práticas recomendadas que
eram opcionais para apps destinados a níveis de API mais baixos se tornam obrigatórias para apps
destinados a níveis de API mais altos.
Android 16 (nível 36 da API)
As mudanças a seguir se aplicam a apps executados no Android 16 ou em versões mais recentes, independente do nível de API a que eles são destinados:
Os jobs em segundo plano iniciados por um serviço em primeiro plano agora precisam obedecer às respectivas cotas de tempo de execução. Isso inclui jobs programados diretamente com
JobScheduler
, bem como jobs criados por outras bibliotecas, como
WorkManager ou DownloadManager
.
Para transferir dados em resposta a uma ação do usuário, considere usar um job de transferência de dados iniciada pelo usuário. Esses jobs estão isentos das cotas comuns.
Android 15 (nível 35 da API)
Os seguintes requisitos se aplicam a apps direcionados ao nível 35 da API ou mais recente:
Android 14 (nível 34 da API)
Os seguintes requisitos se aplicam a apps que segmentam o nível 34 da API ou mais recente:
- É necessário declarar todos os serviços em primeiro plano com os respectivos tipos.
- Os apps precisam solicitar o tipo de permissão adequado para o tipo de trabalho que o
serviço em primeiro plano vai realizar. Cada tipo de serviço em primeiro plano tem um tipo de permissão correspondente. Por exemplo, se um app iniciar um
serviço em primeiro plano que usa a câmera, você precisará solicitar as permissões
FOREGROUND_SERVICE
e
FOREGROUND_SERVICE_CAMERA
. Se um
app for destinado ao nível 34 da API ou mais recente e não
solicitar a permissão específica adequada, o sistema vai gerar uma
SecurityException
.
Android 12 (nível 31 da API)
Os seguintes requisitos se aplicam a apps que segmentam o nível 31 da API ou mais recente:
Android 11 (nível 30 da API)
Os requisitos a seguir se aplicam a apps direcionados ao nível 30 da API ou mais recente:
Android 10 (nível 29 da API)
Os seguintes requisitos se aplicam a apps destinados ao nível 29 ou mais recente da API:
Android 9 (nível 28 da API)
O Android 9 introduz a permissão
FOREGROUND_SERVICE
. Os apps em execução no
Android 9 que usam serviços em primeiro plano precisam ter essa permissão.
Se um app destinado ao nível 28 da API ou a versões mais recentes tentar
criar um serviço em primeiro plano sem solicitar a permissão FOREGROUND_SERVICE
, o sistema vai gerar uma SecurityException
.
O conteúdo e os exemplos de código nesta página estão sujeitos às licenças descritas na Licença de conteúdo. Java e OpenJDK são marcas registradas da Oracle e/ou suas afiliadas.
Última atualização 2025-08-27 UTC.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Não contém as informações de que eu preciso","missingTheInformationINeed","thumb-down"],["Muito complicado / etapas demais","tooComplicatedTooManySteps","thumb-down"],["Desatualizado","outOfDate","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Problema com as amostras / o código","samplesCodeIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-08-27 UTC."],[],[],null,["The foreground service documentation describes the current behavior of\nAndroid foreground services. The documentation gives guidance on best\npractices for most apps, whether or not they target the most recent version\nof Android.\n\nThis page describes some of the most recent important changes to foreground\nservices, and the implications for apps that aren't targeting the most\nrecent version of the Android platform. In many cases, best practices that\nwere optional for apps targeting lower API levels become mandatory for apps\nthat target higher API levels.\n\nAndroid 16 (API level 36)\n\nThe following changes apply to apps that run on Android 16 or higher,\nregardless of what API level they target:\n\n- Background jobs started from a foreground service now must adhere to their\n respective runtime quotas. This includes jobs scheduled directly with\n [`JobScheduler`](/reference/android/app/job/JobScheduler), as well as jobs created by other libraries like\n [WorkManager](/develop/background-work/background-tasks/persistent) or [`DownloadManager`](/reference/android/app/DownloadManager).\n\n To transfer data in response to a user action, consider using a\n [user-initiated data transfer job](/develop/background-work/background-tasks/uidt). These jobs are exempt from the\n ordinary job quotas.\n\nAndroid 15 (API level 35)\n\nThe following requirements apply to apps that target API\nlevel 35 or higher:\n\n- There are new restrictions on how long a `dataSync` foreground service can run. These restrictions are described in [Foreground service timeout\n behavior](/develop/background-work/services/fgs/timeout). Similar restrictions apply to the (new in Android 15) `mediaProcessing` foreground service type.\n- [`BOOT_COMPLETED` foreground services are no longer allowed to launch certain\n foreground services](/about/versions/15/behavior-changes-15#fgs-boot-completed).\n- Apps that hold the `SYSTEM_ALERT_WINDOW` permission are only allowed to launch foreground services from the background if they currently have a visible overlay window (or if they meet one of the other [exemptions from background\n start restrictions](/develop/background-work/services/fgs/restrictions-bg-start#background-start-restriction-exemptions)). Previously, the exemption for those apps was broader.\n\nAndroid 14 (API level 34)\n\nThe following requirements apply to apps that target API\nlevel 34 or higher:\n\n- You must [declare all foreground services](/develop/background-work/services/fgs/declare) with their service types.\n- Apps must request the appropriate permission type for the kind of work the foreground service will be doing. Each [foreground service type](/develop/background-work/services/fgs/service-types) has a corresponding permission type. For example, if an app launches a foreground service that uses the camera, you must request both the [`FOREGROUND_SERVICE`](/reference/android/Manifest.permission#FOREGROUND_SERVICE) and [`FOREGROUND_SERVICE_CAMERA`](/reference/android/Manifest.permission#FOREGROUND_SERVICE_CAMERA) permissions. If an app targets API level 34 or higher and doesn't request the appropriate specific permission, the system throws a `SecurityException`.\n\nAndroid 12 (API level 31)\n\nThe following requirements apply to apps that target API\nlevel 31 or higher:\n\n- Apps are not allowed to launch foreground services while the app is in the background, with a few specific exceptions. For more information, and information about the exceptions to this rule, see [Restrictions on starting\n a foreground service from the background](/develop/background-work/services/fgs/restrictions-bg-start).\n\nAndroid 11 (API level 30)\n\nThe following requirements apply to apps that target API\nlevel 30 or higher:\n\n- If an app's foreground services use the camera or microphone, the app must [declare the service](/develop/background-work/services/fgs/declare) with the [`camera`](/develop/background-work/services/fgs/service-types#camera) or [`microphone`](/develop/background-work/services/fgs/service-types#microphone) service type, respectively.\n\nAndroid 10 (API level 29)\n\nThe following requirements apply to apps that target API\nlevel 29 or higher:\n\n- If an app's foreground services use location information, the app must [declare the service](/develop/background-work/services/fgs/declare) with the [`location`](/develop/background-work/services/fgs/service-types#location) service type.\n\nAndroid 9 (API level 28)\n\nAndroid 9 introduces the\n[`FOREGROUND_SERVICE`](/reference/android/Manifest.permission#FOREGROUND_SERVICE) permission. Apps running on\nAndroid 9 that use foreground services must have that permission.\n\nIf an app that targets API level 28 or higher attempts\nto create a foreground service without requesting the `FOREGROUND_SERVICE`\npermission, the system throws a [`SecurityException`](/reference/java/lang/SecurityException)."]]