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.
연결된 기기
- 매니페스트에서 선언할 포그라운드 서비스 유형
android:foregroundServiceTypeconnectedDevice- 매니페스트에서 선언할 권한
FOREGROUND_SERVICE_CONNECTED_DEVICEstartForeground()에 전달할 상수FOREGROUND_SERVICE_TYPE_CONNECTED_DEVICE- 런타임 기본 요건
다음 조건 중 하나 이상에 해당해야 합니다.
매니페스트에서 다음 권한 중 하나 이상을 선언합니다.
다음 런타임 권한 중 하나 이상을 요청하고 부여받습니다.
UsbManager.requestPermission()을 호출합니다.
- 설명
블루투스, NFC, IR, USB 또는 네트워크 연결이 필요한 외부 기기와의 상호작용입니다.
- 대안
앱에서 외부 기기로 연속 데이터 전송을 실행해야 한다면 대신 호환 기기 관리자를 사용하는 것이 좋습니다. 호환 기기 존재 API를 사용하여 호환 기기가 범위 내에 있는 동안 앱이 계속 실행되도록 합니다.
앱에서 블루투스 기기를 스캔해야 한다면 블루투스 스캔 API를 대신 사용하는 것이 좋습니다.
데이터 동기화
- Foreground service type to declare in manifest under
android:foregroundServiceTypedataSync- Permission to declare in your manifest
FOREGROUND_SERVICE_DATA_SYNC- Constant to pass to
startForeground() FOREGROUND_SERVICE_TYPE_DATA_SYNC- Runtime prerequisites
- None
- Description
Data transfer operations, such as the following:
- Data upload or download
- Backup-and-restore operations
- Import or export operations
- Fetch data
- Local file processing
- Transfer data between a device and the cloud over a network
- Alternatives
See Alternatives to data sync foreground services for detailed information.
Health
- 매니페스트에서 선언할 포그라운드 서비스 유형
android:foregroundServiceTypehealth- 매니페스트에서 선언할 권한
FOREGROUND_SERVICE_HEALTHstartForeground()에 전달할 상수FOREGROUND_SERVICE_TYPE_HEALTH- 런타임 기본 요건
다음 조건 중 하나 이상에 해당해야 합니다.
매니페스트에서
HIGH_SAMPLING_RATE_SENSORS권한을 선언합니다.다음 런타임 권한 중 하나 이상을 요청하고 부여받습니다.
- 설명
운동 추적기 등 피트니스 카테고리의 앱을 지원하기 위한 장기 실행 사용 사례입니다.
위치
- 매니페스트에서 선언할 포그라운드 서비스 유형
android:foregroundServiceTypelocation- 매니페스트에서 선언할 권한
FOREGROUND_SERVICE_LOCATIONstartForeground()에 전달할 상수FOREGROUND_SERVICE_TYPE_LOCATION- 런타임 기본 요건
사용자는 위치 서비스를 사용 설정해야 하며 앱에 다음 런타임 권한 중 하나 이상이 부여되어야 합니다.
- 설명
탐색 및 위치 공유와 같이 위치 액세스가 필요한 장기 실행 사용 사례
- 대안
사용자가 특정 위치에 도달할 때 앱이 트리거되어야 하는 경우 대신 geofence API를 사용하는 것이 좋습니다.
미디어
- 매니페스트에서 선언할 포그라운드 서비스 유형
android:foregroundServiceTypemediaPlayback- 매니페스트에서 선언할 권한
FOREGROUND_SERVICE_MEDIA_PLAYBACKstartForeground()에 전달할 상수FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK- 런타임 기본 요건
- 없음
- 설명
백그라운드에서 오디오 또는 동영상을 계속 재생합니다. Android TV에서 디지털 동영상 녹화 (DVR) 기능을 지원합니다.
- 대안
PIP 동영상을 표시하는 경우 PIP 모드를 사용합니다.
미디어 처리 중
- 매니페스트에서 선언할 포그라운드 서비스 유형
android:foregroundServiceTypemediaProcessing- 매니페스트에서 선언할 권한
FOREGROUND_SERVICE_MEDIA_PROCESSINGstartForeground()에 전달할 상수FOREGROUND_SERVICE_TYPE_MEDIA_PROCESSING- 런타임 기본 요건
- 없음
- 설명
미디어를 다른 형식으로 변환하는 등 미디어 저작물에 시간이 많이 걸리는 작업을 실행하는 서비스입니다. 시스템은 이 서비스가 실행되는 시간을 제한합니다. 일반적으로 이 시간 제한은 24시간 중 6시간입니다. 이 한도는 앱의 모든
mediaProcessing포그라운드 서비스에서 공유됩니다.앱은 다음 시나리오에서 미디어 처리 서비스를 수동으로 중지해야 합니다.
- 트랜스코딩 작업이 완료되거나 실패 상태에 도달하면 서비스가
Service.stopForeground()및Service.stopSelf()를 호출하여 서비스를 완전히 중지하도록 합니다.
- 트랜스코딩 작업이 완료되거나 실패 상태에 도달하면 서비스가
제한 시간에 도달하면 시스템은 서비스의
Service.onTimeout(int, int)메서드를 호출합니다. 이때 서비스는Service.stopSelf()를 호출할 수 있는 몇 초의 시간이 있습니다. 서비스가Service.stopSelf()를 호출하지 않으면 '<fgs_type>의 포그라운드 서비스가 제한 시간 내에 중지되지 않았습니다. <component_name>'라는 오류 메시지와 함께 ANR이 발생합니다.참고:
Service.onTimeout(int, int)는 Android 14 이하에서는 사용할 수 없습니다. 이러한 버전을 실행하는 기기에서 미디어 처리 서비스가 제한 시간에 도달하면 시스템은 즉시 앱을 캐시합니다. 따라서 앱은 제한 시간 알림을 받기 위해 기다리지 않아야 합니다. 대신 포그라운드 서비스를 종료하거나 적절한 시점에 백그라운드 서비스로 변경해야 합니다.
미디어 프로젝션
- 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런타임 권한을 요청하고 부여받습니다.- 설명
음성 녹음기 또는 통신 앱과 같이 백그라운드에서 마이크 캡처를 계속합니다.
전화 통화
- Foreground service type to declare in manifest under
android:foregroundServiceTypephoneCall- Permission to declare in your manifest
FOREGROUND_SERVICE_PHONE_CALL- Constant to pass to
startForeground() FOREGROUND_SERVICE_TYPE_PHONE_CALL- Runtime prerequisites
At least one of these conditions must be true:
- App has declared the
MANAGE_OWN_CALLSpermission in its manifest file.
- App has declared the
- App is the default dialer app through the
ROLE_DIALERrole.
- App is the default dialer app through the
- Description
Continue an ongoing call using the
ConnectionServiceAPIs.- Alternatives
If you need to make phone, video, or VoIP calls, consider using the
android.telecomlibrary.Consider using
CallScreeningServiceto screen calls.
원격 메시지
- 매니페스트에서 선언할 포그라운드 서비스 유형
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.
특수 용도
- Foreground service type to declare in manifest under
android:foregroundServiceTypespecialUse- Permission to declare in your manifest
FOREGROUND_SERVICE_SPECIAL_USE- Constant to pass to
startForeground() FOREGROUND_SERVICE_TYPE_SPECIAL_USE- Runtime prerequisites
- None
- Description
Covers any valid foreground service use cases that aren't covered by the other foreground service types.
In addition to declaring the
FOREGROUND_SERVICE_TYPE_SPECIAL_USEforeground service type, developers should declare use cases in the manifest. To do so, they specify the<property>element within the<service>element. These values and corresponding use cases are reviewed when you submit your app in the Google Play Console. The use cases you provide are free-form, and you should make sure to provide enough information to let the reviewer see why you need to use thespecialUsetype.<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에서 포그라운드 서비스 유형을 선언하는 방법에 관한 자세한 내용은 포그라운드 서비스 및 전체 화면 인텐트 요구사항 이해하기를 참고하세요.