Android 14 (API 수준 34)부터 각 포그라운드 서비스에 적절한 서비스 유형을 선언해야 합니다. 즉, 앱 매니페스트에서
서비스 유형을 선언하고
권한을 요청하는 것 외에도 해당 유형에 적절한 포그라운드
서비스 권한을 요청해야 합니다.FOREGROUND_SERVICE 또한 포그라운드 서비스 유형에 따라 서비스를 실행하기 전에 런타임 권한을 요청해야 할 수도 있습니다.
카메라
- Foreground service type to declare in manifest under
android:foregroundServiceType camera- Permission to declare in your manifest
FOREGROUND_SERVICE_CAMERA- Constant to pass to
startForeground() FOREGROUND_SERVICE_TYPE_CAMERA- Runtime prerequisites
Request and be granted the
CAMERAruntime permission- Description
Continue to access the camera from the background, such as video chat apps that allow for multitasking.
연결된 기기
- Foreground service type to declare in manifest under
android:foregroundServiceTypeconnectedDevice- Permission to declare in your manifest
FOREGROUND_SERVICE_CONNECTED_DEVICE- Constant to pass to
startForeground() FOREGROUND_SERVICE_TYPE_CONNECTED_DEVICE- Runtime prerequisites
At least one of the following conditions must be true:
Declare at least one of the following permissions in your manifest:
Request and be granted at least one of the following runtime permissions:
- Description
Interactions with external devices that require a Bluetooth, NFC, IR, USB, or network connection.
- Alternatives
If your app needs to do continuous data transfer to an external device, consider using the companion device manager instead. Use the companion device presence API to help your app stay running while the companion device is in range.
If your app needs to scan for bluetooth devices, consider using the Bluetooth scan API instead.
데이터 동기화
- `android:foregroundServiceType` 아래 매니페스트에서 선언할 포그라운드 서비스 유형
android:foregroundServiceTypedataSync- 매니페스트에서 선언할 권한
FOREGROUND_SERVICE_DATA_SYNCstartForeground()에 전달할 상수FOREGROUND_SERVICE_TYPE_DATA_SYNC- 런타임 필수사항
- 없음
- 설명
다음과 같은 데이터 전송 작업입니다.
- 데이터 업로드 또는 다운로드
- 백업 및 복원 작업
- 가져오기 또는 내보내기 작업
- 데이터 가져오기
- 로컬 파일 처리
- 네트워크를 통해 기기와 클라우드 간에 데이터 전송
- 대안
자세한 내용은 데이터 동기화 포그라운드 서비스의 대안 을 참고하세요.
Health
- 매니페스트에서 선언할 포그라운드 서비스 유형
android:foregroundServiceTypehealth- 매니페스트에서 선언할 권한
FOREGROUND_SERVICE_HEALTHstartForeground()에 전달할 상수FOREGROUND_SERVICE_TYPE_HEALTH- 런타임 기본 요건
다음 조건 중 하나 이상에 해당해야 합니다.
매니페스트에서
HIGH_SAMPLING_RATE_SENSORS권한을 선언합니다.다음 런타임 권한 중 하나 이상을 요청하고 부여받습니다.
- 설명
운동 추적기 등 피트니스 카테고리의 앱을 지원하기 위한 장기 실행 사용 사례입니다.
위치
- Foreground service type to declare in manifest under
android:foregroundServiceTypelocation- Permission to declare in your manifest
FOREGROUND_SERVICE_LOCATION- Constant to pass to
startForeground() FOREGROUND_SERVICE_TYPE_LOCATION- Runtime prerequisites
The user must have enabled location services and the app must be granted at least one of the following runtime permissions:
- Description
Long-running use cases that require location access, such as navigation and location sharing.
- Alternatives
If your app needs to be triggered when the user reaches specific locations, consider using the geofence API instead.
미디어
- 매니페스트에서 선언할 포그라운드 서비스 유형
android:foregroundServiceTypemediaPlayback- 매니페스트에서 선언할 권한
FOREGROUND_SERVICE_MEDIA_PLAYBACKstartForeground()에 전달할 상수FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK- 런타임 기본 요건
- 없음
- 설명
백그라운드에서 오디오 또는 동영상을 계속 재생합니다. Android TV에서 디지털 동영상 녹화 (DVR) 기능을 지원합니다.
- 대안
PIP 동영상을 표시하는 경우 PIP 모드를 사용합니다.
미디어 처리 중
- Foreground service type to declare in manifest under
android:foregroundServiceTypemediaProcessing- Permission to declare in your manifest
FOREGROUND_SERVICE_MEDIA_PROCESSING- Constant to pass to
startForeground() FOREGROUND_SERVICE_TYPE_MEDIA_PROCESSING- Runtime prerequisites
- None
- Description
Service for performing time-consuming operations on media assets, like converting media to different formats. The system allows this service a limited time to run; under normal circumstances, this time limit would be 6 hours out of every 24. (This limit is shared by all of an app's
mediaProcessingforeground services.)Your app should manually stop the media processing service in the following scenario:
- When the transcoding operation finishes or reaches a failure state, have the
service call
Service.stopForeground()andService.stopSelf()to stop the service completely.
- When the transcoding operation finishes or reaches a failure state, have the
service call
If the timeout period is reached, the system calls the service's
Service.onTimeout(int, int)method. At this time, the service has a few seconds to callService.stopSelf(). If the service does not callService.stopSelf(), an ANR will occur with this error message: "A foreground service of <fgs_type> did not stop within its timeout: <component_name>".Note:
Service.onTimeout(int, int)is not available on Android 14 or lower. On devices running those versions, if a media processing service reaches the timeout period, the system immediately caches the app. For this reason, your app shouldn't wait to get a timeout notification. Instead, it should terminate the foreground service or change it to a background service as soon as appropriate.
미디어 프로젝션
- Foreground service type to declare in manifest under
android:foregroundServiceTypemediaProjection- Permission to declare in your manifest
FOREGROUND_SERVICE_MEDIA_PROJECTION- Constant to pass to
startForeground() FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION- Runtime prerequisites
Call the
createScreenCaptureIntent()method before starting the foreground service. Doing so shows a permission notification to the user; the user must grant the permission before you can create the service.After you have created the foreground service, you can call
MediaProjectionManager.getMediaProjection().- Description
Project content to non-primary display or external device using the
MediaProjectionAPIs. This content doesn't have to be exclusively media content.- Alternatives
To stream media to another device, use the Google Cast SDK.
마이크
- `android:foregroundServiceType` 아래 매니페스트에서 선언할 포그라운드 서비스 유형
android:foregroundServiceTypemicrophone- 매니페스트에서 선언할 권한
FOREGROUND_SERVICE_MICROPHONEstartForeground()에 전달할 상수FOREGROUND_SERVICE_TYPE_MICROPHONE- 런타임 필수 조건
RECORD_AUDIO런타임 권한을 요청하고 부여받습니다.- 설명
음성 녹음기 또는 통신 앱과 같이 백그라운드에서 마이크 캡처를 계속합니다.
전화 통화
- 매니페스트에서 선언할 포그라운드 서비스 유형
android:foregroundServiceTypephoneCall- 매니페스트에서 선언할 권한
FOREGROUND_SERVICE_PHONE_CALLstartForeground()에 전달할 상수FOREGROUND_SERVICE_TYPE_PHONE_CALL- 런타임 기본 요건
다음 조건 중 하나 이상에 해당해야 합니다.
- 앱이 매니페스트 파일에서
MANAGE_OWN_CALLS권한을 선언했습니다.
- 앱이 매니페스트 파일에서
- 앱이
ROLE_DIALER역할을 통해 기본 전화 앱입니다.
- 앱이
- 설명
ConnectionServiceAPI를 사용하여 진행 중인 통화를 계속합니다.- 대안
전화, 영상 통화 또는 VoIP 통화를 해야 하는 경우
android.telecom라이브러리를 사용하는 것이 좋습니다.CallScreeningService을 사용하여 통화를 스크린하는 것이 좋습니다.
원격 메시지
- 매니페스트에서 선언할 포그라운드 서비스 유형
android:foregroundServiceTyperemoteMessaging- 매니페스트에서 선언할 권한
FOREGROUND_SERVICE_REMOTE_MESSAGINGstartForeground()에 전달할 상수FOREGROUND_SERVICE_TYPE_REMOTE_MESSAGING- 런타임 기본 요건
- 없음
- 설명
- 문자 메시지를 한 기기에서 다른 기기로 전송합니다. 사용자가 기기를 전환할 때 사용자의 메시지 작업의 연속성을 지원합니다.
짧은 서비스
- Foreground service type to declare in manifest under
android:foregroundServiceTypeshortService- Permission to declare in your manifest
- None
- Constant to pass to
startForeground() FOREGROUND_SERVICE_TYPE_SHORT_SERVICE- Runtime prerequisites
- None
- Description
Quickly finish critical work that cannot be interrupted or postponed.
This type has some unique characteristics:
- Can only run for a short period of time (about 3 minutes).
- No support for sticky foreground services.
- Cannot start other foreground services.
- Doesn't require a type-specific permission, though it still
requires the
FOREGROUND_SERVICEpermission. - A
shortServicecan only change to another service type if the app is currently eligible to start a new foreground service. - A foreground service can change its type to
shortServiceat any time, at which point the timeout period begins.
The timeout for shortService begins from the moment that
Service.startForeground()is called. The app is expected to callService.stopSelf()orService.stopForeground()before the timeout occurs. Otherwise, the newService.onTimeout()is called, giving apps a brief opportunity to callstopSelf()orstopForeground()to stop their service.A short time after
Service.onTimeout()is called, the app enters a cached state and is no longer considered to be in the foreground, unless the user is actively interacting with the app. A short time after the app is cached and the service has not stopped, the app receives an ANR. The ANR message mentionsFOREGROUND_SERVICE_TYPE_SHORT_SERVICE. For these reasons, it's considered best practice to implement theService.onTimeout()callback.The
Service.onTimeout()callback doesn't exist on Android 13 and lower. If the same service runs on such devices, it doesn't receive a timeout, nor does it ANR. Make sure that your service stops as soon as it finishes the processing task, even if it hasn't received theService.onTimeout()callback yet.It's important to note that if the timeout of the
shortServiceis not respected, the app will ANR even if it has other valid foreground services or other app lifecycle processes running.If an app is visible to the user or satisfies one of the exemptions that allow foreground services to be started from the background, calling
Service.StartForeground()again with theFOREGROUND_SERVICE_TYPE_SHORT_SERVICEparameter extends the timeout by another 3 minutes. If the app isn't visible to the user and doesn't satisfy one of the exemptions, any attempt to start another foreground service, regardless of type, causes aForegroundServiceStartNotAllowedException.If a user disables battery optimization for your app, it's still affected by the timeout of shortService FGS.
If you start a foreground service that includes the
shortServicetype and another foreground service type, the system ignores theshortServicetype declaration. However, the service must still adhere to the prerequisites of the other declared types. For more information, see the Foreground services documentation.
특수 용도
- 매니페스트에서 선언할 포그라운드 서비스 유형
android:foregroundServiceTypespecialUse- 매니페스트에서 선언할 수 있는 권한
FOREGROUND_SERVICE_SPECIAL_USEstartForeground()에 전달할 상수FOREGROUND_SERVICE_TYPE_SPECIAL_USE- 런타임 기본 요건
- 없음
- 설명
다른 포그라운드 서비스 유형에서 다루지 않는 유효한 포그라운드 서비스 사용 사례를 다룹니다.
개발자는
FOREGROUND_SERVICE_TYPE_SPECIAL_USE포그라운드 서비스 유형을 선언하는 것 외에도 매니페스트에서 사용 사례를 선언해야 합니다. 이렇게 하려면<service>요소 내에서<property>요소를 지정해야 합니다. 이러한 값과 해당 사용 사례는 Google Play Console에서 앱을 제출할 때 검토됩니다. 용도 제공하는 케이스는 자유 형식이므로specialUse를 사용해야 하는 이유를 검토자가 알 수 있도록 관련 정보 있습니다.<service android:name="fooService" android:foregroundServiceType="specialUse"> <property android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE" android:value="explanation_for_special_use"/> </service>
시스템 제외됨
- 매니페스트에서 선언할 포그라운드 서비스 유형
android:foregroundServiceTypesystemExempted- 매니페스트에서 선언할 권한
FOREGROUND_SERVICE_SYSTEM_EXEMPTEDstartForeground()에 전달할 상수FOREGROUND_SERVICE_TYPE_SYSTEM_EXEMPTED- 런타임 기본 요건
- 없음
- 설명
포그라운드 서비스를 계속 사용하기 위해 시스템 애플리케이션 및 특정 시스템 통합을 위해 예약됩니다.
이 유형을 사용하려면 앱이 다음 기준 중 하나 이상을 충족해야 합니다.
- 기기가 데모 모드 상태입니다.
- 앱이 기기 소유자입니다.
- 앱이 프로파일러 소유자입니다.
ROLE_EMERGENCY역할이 있는 위급 정보 앱입니다.- 기기 관리자앱입니다.
SCHEDULE_EXACT_ALARM또는USE_EXACT_ALARM권한을 보유한 앱VPN 앱 (설정 > 네트워크 및 인터넷 > VPN을 사용하여 구성됨)
이 외의 경우에 이 유형을 선언하면 시스템에서
ForegroundServiceTypeNotAllowedException이 발생합니다.
포그라운드 서비스 유형 사용에 관한 Google Play 정책 시행
앱이 Android 14 이상을 타겟팅하는 경우 Play Console의 앱 콘텐츠 페이지 (정책 > 앱 콘텐츠)에서 앱의 포그라운드 서비스 유형을 선언해야 합니다. Play Console에서 포그라운드 서비스 유형을 선언하는 방법에 관한 자세한 내용은 포그라운드 서비스 및 전체 화면 인텐트 요구사항 이해하기를 참고하세요.