Modifications apportées aux services de premier plan
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
La documentation sur les services de premier plan décrit le comportement actuel des services de premier plan Android. La documentation fournit des conseils sur les bonnes pratiques à suivre pour la plupart des applications, qu'elles ciblent ou non la version la plus récente d'Android.
Cette page décrit certaines des modifications importantes les plus récentes apportées aux services de premier plan, ainsi que leurs implications pour les applications qui ne ciblent pas la version la plus récente de la plate-forme Android. Dans de nombreux cas, les bonnes pratiques qui étaient facultatives pour les applications ciblant des niveaux d'API inférieurs deviennent obligatoires pour les applications ciblant des niveaux d'API supérieurs.
Android 16 (niveau d'API 36)
Les modifications suivantes s'appliquent aux applications qui s'exécutent sur Android 16 ou version ultérieure, quel que soit le niveau d'API qu'elles ciblent :
Les jobs en arrière-plan lancés à partir d'un service de premier plan doivent désormais respecter leurs quotas d'exécution respectifs. Cela inclut les tâches planifiées directement avec JobScheduler
, ainsi que les tâches créées par d'autres bibliothèques telles que WorkManager ou DownloadManager
.
Pour transférer des données en réponse à une action de l'utilisateur, envisagez d'utiliser une tâche de transfert de données déclenchée par l'utilisateur. Ces tâches sont exemptées des quotas de tâches ordinaires.
Android 15 (niveau d'API 35)
Les exigences suivantes s'appliquent aux applications qui ciblent le niveau d'API 35 ou supérieur :
Android 14 (niveau d'API 34)
Les exigences suivantes s'appliquent aux applications qui ciblent le niveau d'API 34 ou supérieur :
- Vous devez déclarer tous les services de premier plan avec leurs types de services.
- Les applications doivent demander le type d'autorisation approprié pour le type de travail que le service de premier plan effectuera. Chaque type de service de premier plan correspond à un type d'autorisation. Par exemple, si une application lance un service de premier plan qui utilise l'appareil photo, vous devez demander les autorisations
FOREGROUND_SERVICE
et FOREGROUND_SERVICE_CAMERA
. Si une application cible le niveau d'API 34 ou supérieur et ne demande pas l'autorisation spécifique appropriée, le système génère une SecurityException
.
Android 12 (niveau d'API 31)
Les exigences suivantes s'appliquent aux applications qui ciblent le niveau d'API 31 ou supérieur :
Android 11 (niveau d'API 30)
Les exigences suivantes s'appliquent aux applications qui ciblent le niveau d'API 30 ou supérieur :
- Si les services de premier plan d'une application utilisent l'appareil photo ou le micro, l'application doit déclarer le service avec le type de service
camera
ou microphone
, respectivement.
Android 10 (niveau d'API 29)
Les exigences suivantes s'appliquent aux applications qui ciblent le niveau d'API 29 ou supérieur :
- Si les services de premier plan d'une application utilisent des informations de localisation, l'application doit déclarer le service avec le type de service
location
.
Android 9 (niveau d'API 28)
Android 9 introduit l'autorisation FOREGROUND_SERVICE
. Les applications exécutées sur Android 9 qui utilisent des services de premier plan doivent disposer de cette autorisation.
Si une application ciblant le niveau d'API 28 ou supérieur tente de créer un service de premier plan sans demander l'autorisation FOREGROUND_SERVICE
, le système génère une SecurityException
.
Le contenu et les exemples de code de cette page sont soumis aux licences décrites dans la Licence de contenu. Java et OpenJDK sont des marques ou des marques déposées d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/08/27 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Il n'y a pas l'information dont j'ai besoin","missingTheInformationINeed","thumb-down"],["Trop compliqué/Trop d'étapes","tooComplicatedTooManySteps","thumb-down"],["Obsolète","outOfDate","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Mauvais exemple/Erreur de code","samplesCodeIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 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)."]]