Android 14 (API 수준 34)부터는 각 포그라운드 서비스에 적절한 서비스 유형을 선언해야 합니다. 즉, FOREGROUND_SERVICE
권한을 요청하는 것 외에도 앱 매니페스트에서 서비스 유형을 선언하고 이 유형에 적절한 포그라운드 서비스 권한도 요청해야 합니다. 또한 포그라운드 서비스 유형에 따라 서비스를 시작하기 전에 런타임 권한을 요청해야 할 수도 있습니다.
카메라
- 매니페스트에서
android:foregroundServiceType
아래 선언할 포그라운드 서비스 유형 camera
- 매니페스트에서 선언할 권한
FOREGROUND_SERVICE_CAMERA
startForeground()
에 전달할 상수FOREGROUND_SERVICE_TYPE_CAMERA
- 런타임 기본 요건
CAMERA
런타임 권한 요청 및 부여참고:
CAMERA
런타임 권한에는 사용 중 제한사항이 적용됩니다. 이러한 이유로 몇 가지 예외를 제외하고 앱이 백그라운드에 있는 동안에는camera
포그라운드 서비스를 만들 수 없습니다. 자세한 내용은 사용 중 권한이 필요한 포그라운드 서비스 시작 제한사항을 참고하세요.- 설명
멀티태스킹을 허용하는 영상 채팅 앱과 같이 백그라운드에서 카메라에 계속 액세스합니다.
연결된 기기
- 매니페스트에서 선언할 포그라운드 서비스 유형
android:foregroundServiceType
connectedDevice
- 매니페스트에서 선언할 권한
FOREGROUND_SERVICE_CONNECTED_DEVICE
startForeground()
에 전달할 상수FOREGROUND_SERVICE_TYPE_CONNECTED_DEVICE
- 런타임 기본 요건
다음 조건 중 하나 이상에 해당해야 합니다.
매니페스트에서 다음 권한 중 하나 이상을 선언합니다.
다음 런타임 권한 중 하나 이상을 요청하고 부여받습니다.
UsbManager.requestPermission()
을 호출합니다.
- 설명
블루투스, NFC, IR, USB 또는 네트워크 연결이 필요한 외부 기기와의 상호작용입니다.
- 대안
앱에서 외부 기기로 데이터를 계속 전송해야 한다면 대신 호환 기기 관리자를 사용해 보세요. 호환 기기 접속 상태 API를 사용하면 호환 기기가 범위 내에 있는 동안 앱이 계속 실행되도록 할 수 있습니다.
앱에서 블루투스 기기를 검색해야 한다면 대신 블루투스 검색 API를 사용해 보세요.
데이터 동기화
- 매니페스트에서 선언할 포그라운드 서비스 유형
android:foregroundServiceType
dataSync
- 매니페스트에서 선언할 권한
FOREGROUND_SERVICE_DATA_SYNC
startForeground()
에 전달할 상수FOREGROUND_SERVICE_TYPE_DATA_SYNC
- 런타임 기본 요건
- 없음
- 설명
다음과 같은 데이터 전송 작업입니다.
- 데이터 업로드 또는 다운로드
- 백업 및 복원 작업
- 가져오기 또는 내보내기 작업
- 데이터 가져오기
- 로컬 파일 처리
- 네트워크를 통해 기기와 클라우드 간에 데이터 전송
- 대안
자세한 내용은 데이터 동기화 포그라운드 서비스 대안을 참고하세요.
Health
- 매니페스트에서 선언할 포그라운드 서비스 유형
android:foregroundServiceType
health
- 매니페스트에서 선언할 권한
FOREGROUND_SERVICE_HEALTH
startForeground()
에 전달할 상수FOREGROUND_SERVICE_TYPE_HEALTH
- 런타임 기본 요건
다음 조건 중 하나 이상에 해당해야 합니다.
매니페스트에서
HIGH_SAMPLING_RATE_SENSORS
권한을 선언합니다.다음 런타임 권한 중 하나 이상을 요청하고 부여받습니다.
참고:
BODY_SENSORS
런타임 권한에는 사용 중 제한사항이 적용됩니다. 이러한 이유로 몇 가지 예외를 제외하고 앱이 백그라운드에 있는 동안 생체 신호 센서를 사용하는health
포그라운드 서비스는 만들 수 없습니다. 자세한 내용은 사용 중 권한이 필요한 포그라운드 서비스 시작 제한사항을 참고하세요.- 설명
운동 추적기 등 피트니스 카테고리의 앱을 지원하기 위한 장기 실행 사용 사례입니다.
위치
- 매니페스트에서 선언할 포그라운드 서비스 유형
android:foregroundServiceType
location
- 매니페스트에서 선언할 수 있는 권한
FOREGROUND_SERVICE_LOCATION
startForeground()
에 전달할 상수FOREGROUND_SERVICE_TYPE_LOCATION
- 런타임 기본 요건
사용자가 위치 서비스를 사용 설정해야 하며 앱에 다음 런타임 권한 중 하나 이상이 부여되어야 합니다.
참고: 사용자가 위치 서비스를 사용 설정하고 런타임 권한에 대한 액세스 권한을 부여했는지 확인하려면
PermissionChecker#checkSelfPermission()
를 사용하세요.참고: 위치 런타임 권한에는 사용 중 제한사항이 적용됩니다. 따라서
ACCESS_BACKGROUND_LOCATION
런타임 권한을 부여받지 않는 한 앱이 백그라운드에 있는 동안location
포그라운드 서비스를 만들 수 없습니다. 자세한 내용은 사용 중 권한이 필요한 포그라운드 서비스 시작에 관한 제한사항을 참고하세요.- 설명
탐색 및 위치 공유와 같이 위치 액세스가 필요한 장기 실행 사용 사례
- 대안
사용자가 특정 위치에 도달할 때 앱을 트리거해야 한다면 대신 지오펜싱 API를 사용하는 것이 좋습니다.
미디어
- 매니페스트에서 선언할 포그라운드 서비스 유형
android:foregroundServiceType
mediaPlayback
- 매니페스트에서 선언할 권한
FOREGROUND_SERVICE_MEDIA_PLAYBACK
startForeground()
에 전달할 상수FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK
- 런타임 기본 요건
- 없음
- 설명
- 백그라운드에서 오디오 또는 동영상을 계속 재생합니다. Android TV에서 디지털 동영상 녹화 (DVR) 기능을 지원합니다.
- 대안
- PIP 모드를 표시하는 경우에는 PIP 모드를 사용합니다.
미디어 프로젝션
- 매니페스트에서 선언할 포그라운드 서비스 유형
android:foregroundServiceType
mediaProjection
- 매니페스트에서 선언할 권한
FOREGROUND_SERVICE_MEDIA_PROJECTION
startForeground()
에 전달할 상수FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION
- 런타임 기본 요건
포그라운드 서비스를 시작하기 전에
createScreenCaptureIntent()
메서드를 호출합니다. 이렇게 하면 사용자에게 권한 알림이 표시됩니다. 사용자가 권한을 부여해야 서비스를 만들 수 있습니다.포그라운드 서비스를 만든 후
MediaProjectionManager.getMediaProjection()
를 호출할 수 있습니다.- 설명
MediaProjection
API를 사용하여 기본이 아닌 디스플레이 또는 외부 기기에 콘텐츠를 전송합니다. 이 콘텐츠는 반드시 미디어 콘텐츠일 필요는 없습니다.- 대안
미디어를 다른 기기로 스트리밍하려면 Google Cast SDK를 사용하세요.
마이크
- 매니페스트에서 선언할 포그라운드 서비스 유형
android:foregroundServiceType
microphone
- 매니페스트에서 선언할 권한
FOREGROUND_SERVICE_MICROPHONE
startForeground()
에 전달할 상수FOREGROUND_SERVICE_TYPE_MICROPHONE
- 런타임 기본 요건
RECORD_AUDIO
런타임 권한을 요청하고 부여받습니다.참고:
RECORD_AUDIO
런타임 권한에는 사용 중 제한사항이 적용됩니다. 이러한 이유로 몇 가지 예외를 제외하고 앱이 백그라운드에 있는 동안에는microphone
포그라운드 서비스를 만들 수 없습니다. 자세한 내용은 사용 중 권한이 필요한 포그라운드 서비스 시작 제한사항을 참고하세요.- 설명
음성 녹음기 또는 통신 앱과 같이 백그라운드에서 마이크 캡처를 계속합니다.
전화 통화
- 매니페스트에서 선언할 포그라운드 서비스 유형
android:foregroundServiceType
phoneCall
- 매니페스트에서 선언할 권한
FOREGROUND_SERVICE_PHONE_CALL
startForeground()
에 전달할 상수FOREGROUND_SERVICE_TYPE_PHONE_CALL
- 런타임 기본 요건
다음 조건 중 하나 이상에 해당해야 합니다.
- 앱이 매니페스트 파일에서
MANAGE_OWN_CALLS
권한을 선언했습니다.
- 앱이 매니페스트 파일에서
- 앱이
ROLE_DIALER
역할을 통해 기본 다이얼러 앱입니다.
- 앱이
- 설명
ConnectionService
API를 사용하여 진행 중인 호출을 계속합니다.- 대안
전화, 영상, VoIP 통화를 이용해야 한다면
android.telecom
라이브러리를 사용해 보세요.CallScreeningService
를 사용하여 통화를 선택해 보세요.
원격 메시지
- Foreground service type to declare in manifest under
android:foregroundServiceType
remoteMessaging
- Permission to declare in your manifest
FOREGROUND_SERVICE_REMOTE_MESSAGING
- Constant to pass to
startForeground()
FOREGROUND_SERVICE_TYPE_REMOTE_MESSAGING
- Runtime prerequisites
- None
- Description
- Transfer text messages from one device to another. Assists with continuity of a user's messaging tasks when they switch devices.
짧은 서비스
- Foreground service type to declare in manifest under
android:foregroundServiceType
shortService
- 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_SERVICE
permission. - A
shortService
can 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
shortService
at 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
shortService
is 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_SERVICE
parameter 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
shortService
type and another foreground service type, the system ignores theshortService
type declaration. However, the service must still adhere to the prerequisites of the other declared types. For more information, see the Foreground services documentation.
특수 용도
- 매니페스트에서 선언할 포그라운드 서비스 유형
android:foregroundServiceType
specialUse
- 매니페스트에서 선언할 수 있는 권한
FOREGROUND_SERVICE_SPECIAL_USE
startForeground()
에 전달할 상수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:foregroundServiceType
systemExempted
- 매니페스트에서 선언할 수 있는 권한
FOREGROUND_SERVICE_SYSTEM_EXEMPTED
startForeground()
에 전달할 상수FOREGROUND_SERVICE_TYPE_SYSTEM_EXEMPTED
- 런타임 기본 요건
- 없음
- 설명
시스템 애플리케이션 및 특정 시스템 통합을 위해 예약되어 있으며, 포그라운드 서비스를 계속 사용할 수 있습니다
이 유형을 사용하려면 앱이 다음 기준 중 하나 이상을 충족해야 합니다.
- 기기가 데모 모드 상태입니다.
- 앱이 기기 소유자입니다.
- 앱이 프로파일러 소유자입니다.
ROLE_EMERGENCY
역할이 있는 위급 정보 앱입니다.- 기기 관리자앱입니다.
SCHEDULE_EXACT_ALARM
또는USE_EXACT_ALARM
권한을 보유하고 있으며 백그라운드에서 알람을 계속 실행하는 포그라운드 서비스 햅틱 전용 알람 포함VPN 앱 (설정 > 네트워크 및 인터넷 > VPN에서 구성됨)
이 외의 경우에 이 유형을 선언하면 시스템에서
ForegroundServiceTypeNotAllowedException
이 발생합니다.
포그라운드 서비스 유형 사용에 관한 Google Play 정책 시행
앱이 Android 14 이상을 타겟팅한다면 Play Console의 앱 콘텐츠 페이지 (정책 > 앱 콘텐츠)에서 앱의 포그라운드 서비스 유형을 선언해야 합니다. Play Console에서 포그라운드 서비스 유형을 선언하는 방법에 관한 자세한 내용은 포그라운드 서비스 및 전체 화면 인텐트 요구사항 이해를 참고하세요.