Android 14 (API 수준 34)부터는 각 포그라운드 서비스에 적절한 서비스 유형을 선언해야 합니다. 즉, 앱 매니페스트에서 서비스 유형을 선언하고 FOREGROUND_SERVICE
권한을 요청하는 것 외에도 해당 유형에 적절한 포그라운드 서비스 권한을 요청해야 합니다. 또한 포그라운드 서비스 유형에 따라 서비스를 실행하기 전에 런타임 권한을 요청해야 할 수도 있습니다.
카메라
android:foregroundServiceType
아래 매니페스트에서 선언할 포그라운드 서비스 유형camera
- 매니페스트에서 선언할 권한
FOREGROUND_SERVICE_CAMERA
startForeground()
에 전달할 상수FOREGROUND_SERVICE_TYPE_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
권한을 선언합니다.다음 런타임 권한 중 하나 이상을 요청하고 부여받습니다.
- 설명
운동 추적기 등 피트니스 카테고리의 앱을 지원하기 위한 장기 실행 사용 사례입니다.
위치
- 매니페스트에서 선언할 포그라운드 서비스 유형
android:foregroundServiceType
location
- 매니페스트에서 선언할 권한
FOREGROUND_SERVICE_LOCATION
startForeground()
에 전달할 상수FOREGROUND_SERVICE_TYPE_LOCATION
- 런타임 기본 요건
사용자는 위치 서비스를 사용 설정해야 하며 앱에 다음 런타임 권한 중 하나 이상이 부여되어야 합니다.
- 설명
탐색 및 위치 공유와 같이 위치 액세스가 필요한 장기 실행 사용 사례
- 대안
사용자가 특정 위치에 도달할 때 앱이 트리거되어야 하는 경우 대신 geofence API를 사용하는 것이 좋습니다.
미디어
- Foreground service type to declare in manifest under
android:foregroundServiceType
mediaPlayback
- Permission to declare in your manifest
FOREGROUND_SERVICE_MEDIA_PLAYBACK
- Constant to pass to
startForeground()
FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK
- Runtime prerequisites
- None
- Description
Continue audio or video playback from the background. Support Digital Video Recording (DVR) functionality on Android TV.
- Alternatives
If you're showing picture-in-picture video, use Picture-in-Picture mode.
미디어 처리 중
- Foreground service type to declare in manifest under
android:foregroundServiceType
mediaProcessing
- 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
mediaProcessing
foreground 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.
미디어 프로젝션
- 매니페스트에서 선언할 포그라운드 서비스 유형
android:foregroundServiceType
mediaProjection
- 매니페스트에서 선언할 권한
FOREGROUND_SERVICE_MEDIA_PROJECTION
startForeground()
에 전달할 상수FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION
- 런타임 기본 요건
포그라운드 서비스를 시작하기 전에
createScreenCaptureIntent()
메서드를 호출합니다. 이렇게 하면 사용자에게 권한 알림이 표시됩니다. 서비스를 만들려면 사용자가 권한을 부여해야 합니다.포그라운드 서비스를 만든 후
MediaProjectionManager.getMediaProjection()
를 호출할 수 있습니다.- 설명
MediaProjection
API를 사용하여 기본이 아닌 디스플레이 또는 외부 기기에 콘텐츠를 투사합니다. 이 콘텐츠는 반드시 미디어 콘텐츠일 필요는 없습니다.- 대안
다른 기기로 미디어를 스트리밍하려면 Google Cast SDK를 사용하세요.
마이크
- Foreground service type to declare in manifest under
android:foregroundServiceType
microphone
- Permission to declare in your manifest
FOREGROUND_SERVICE_MICROPHONE
- Constant to pass to
startForeground()
FOREGROUND_SERVICE_TYPE_MICROPHONE
- Runtime prerequisites
Request and be granted the
RECORD_AUDIO
runtime permission.- Description
Continue microphone capture from the background, such as voice recorders or communication apps.
전화 통화
- Foreground service type to declare in manifest under
android:foregroundServiceType
phoneCall
- 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_CALLS
permission in its manifest file.
- App has declared the
- App is the default dialer app through the
ROLE_DIALER
role.
- App is the default dialer app through the
- Description
Continue an ongoing call using the
ConnectionService
APIs.- Alternatives
If you need to make phone, video, or VoIP calls, consider using the
android.telecom
library.Consider using
CallScreeningService
to screen calls.
원격 메시지
- 매니페스트에서 선언할 포그라운드 서비스 유형
android:foregroundServiceType
remoteMessaging
- 매니페스트에서 선언할 권한
FOREGROUND_SERVICE_REMOTE_MESSAGING
startForeground()
에 전달할 상수FOREGROUND_SERVICE_TYPE_REMOTE_MESSAGING
- 런타임 기본 요건
- 없음
- 설명
- 문자 메시지를 한 기기에서 다른 기기로 전송합니다. 사용자가 기기를 전환할 때 사용자의 메시지 작업의 연속성을 지원합니다.
짧은 서비스
- 매니페스트에서 선언할 포그라운드 서비스 유형
android:foregroundServiceType
shortService
- 매니페스트에서 선언할 권한
- 없음
startForeground()
에 전달할 상수FOREGROUND_SERVICE_TYPE_SHORT_SERVICE
- 런타임 기본 요건
- 없음
- 설명
중단하거나 연기할 수 없는 중요한 작업을 신속하게 완료합니다.
이 유형에는 몇 가지 고유한 특성이 있습니다.
- 짧은 기간(약 3분) 동안만 실행할 수 있습니다.
- 고정 포그라운드 서비스는 지원되지 않습니다.
- 다른 포그라운드 서비스는 시작할 수 없습니다.
- 유형별 권한은 필요하지 않지만
FOREGROUND_SERVICE
권한은 필요합니다. shortService
는 앱이 현재 새로운 포그라운드 서비스를 시작할 수 있는 경우에만 다른 서비스 유형으로 변경할 수 있습니다.- 포그라운드 서비스는 언제든지
shortService
로 유형을 변경할 수 있으며 이 시점부터 제한 시간이 시작됩니다.
shortService의 제한 시간은
Service.startForeground()
가 호출되는 시점부터 시작됩니다. 앱은 제한 시간이 발생하기 전에Service.stopSelf()
또는Service.stopForeground()
를 호출해야 합니다. 그러지 않으면 새Service.onTimeout()
이 호출되어 앱이stopSelf()
또는stopForeground()
를 호출하여 서비스를 중지할 수 있는 짧은 기회를 제공합니다.Service.onTimeout()
이 호출되고 잠시 후에 앱이 캐시된 상태가 되고 사용자가 앱과 활발하게 상호작용하지 않는 한 더 이상 포그라운드에 있는 것으로 간주되지 않습니다. 앱이 캐시되고 서비스가 중지되지 않은 잠시 후에 앱이 ANR을 수신합니다. ANR 메시지에서FOREGROUND_SERVICE_TYPE_SHORT_SERVICE
를 언급합니다. 이러한 이유로Service.onTimeout()
콜백을 구현하는 것이 좋습니다.Android 13 이하에는
Service.onTimeout()
콜백이 없습니다. 이러한 기기에서 동일한 서비스가 실행되는 경우 제한 시간과 ANR을 모두 수신하지 않습니다. 아직Service.onTimeout()
콜백을 수신하지 않았더라도 처리 작업이 완료되는 즉시 서비스가 중지되는지 확인합니다.shortService
의 제한 시간이 준수되지 않으면 앱에 유효한 다른 포그라운드 서비스나 다른 앱 수명 주기 프로세스가 실행 중이더라도 ANR이 발생한다는 점에 유의해야 합니다.앱이 사용자에게 표시되거나 포그라운드 서비스가 백그라운드에서 시작되도록 허용하는 예외 중 하나를 충족하는 경우
FOREGROUND_SERVICE_TYPE_SHORT_SERVICE
매개변수로Service.StartForeground()
를 다시 호출하면 제한 시간이 3분 더 연장됩니다. 앱이 사용자에게 표시되지 않고 예외 중 하나를 충족하지 않는 경우 유형과 관계없이 다른 포그라운드 서비스를 시작하려고 하면ForegroundServiceStartNotAllowedException
이 발생합니다.사용자가 앱의 배터리 최적화를 사용 중지해도 shortService FGS의 제한 시간에 영향을 받습니다.
shortService
유형과 다른 포그라운드 서비스 유형이 포함된 포그라운드 서비스를 시작하면 시스템에서shortService
유형 선언을 무시합니다. 하지만 서비스는 여전히 선언된 다른 유형의 기본 요건을 준수해야 합니다. 자세한 내용은 포그라운드 서비스 문서를 참고하세요.
특수 용도
- 매니페스트에서 선언할 포그라운드 서비스 유형
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 정책 시행
If your app targets Android 14 or higher, you'll need to declare your app's foreground service types in the Play Console's app content page (Policy > App content). For more information on how to declare your foreground service types in Play Console, see Understanding foreground service and full-screen intent requirements.