Android 14 (API 수준 34)부터는 각 포그라운드 서비스에 적절한 서비스 유형을 선언해야 합니다. 즉, FOREGROUND_SERVICE
권한을 요청하는 것 외에도 앱 매니페스트에서 서비스 유형을 선언하고 이 유형에 적절한 포그라운드 서비스 권한도 요청해야 합니다. 또한 포그라운드 서비스 유형에 따라 서비스를 시작하기 전에 런타임 권한을 요청해야 할 수도 있습니다.
카메라
- 매니페스트에서
android:foregroundServiceType
아래 선언할 포그라운드 서비스 유형 camera
- 매니페스트에서 선언할 권한
FOREGROUND_SERVICE_CAMERA
startForeground()
에 전달할 상수FOREGROUND_SERVICE_TYPE_CAMERA
- 런타임 기본 요건
CAMERA
런타임 권한 요청 및 부여참고:
CAMERA
런타임 권한에는 사용 중 제한사항이 적용됩니다. 이러한 이유로 몇 가지 예외를 제외하고 앱이 백그라운드에 있는 동안에는camera
포그라운드 서비스를 만들 수 없습니다. 자세한 내용은 사용 중 권한이 필요한 포그라운드 서비스 시작 제한사항을 참고하세요.- 설명
멀티태스킹을 허용하는 영상 채팅 앱과 같이 백그라운드에서 카메라에 계속 액세스합니다.
연결된 기기
- Foreground service type to declare in manifest under
android:foregroundServiceType
connectedDevice
- 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
dataSync
- 매니페스트에서 선언할 권한
FOREGROUND_SERVICE_DATA_SYNC
startForeground()
에 전달할 상수FOREGROUND_SERVICE_TYPE_DATA_SYNC
- 런타임 기본 요건
- 없음
- 설명
다음과 같은 데이터 전송 작업입니다.
- 데이터 업로드 또는 다운로드
- 백업 및 복원 작업
- 가져오기 또는 내보내기 작업
- 데이터 가져오기
- 로컬 파일 처리
- 네트워크를 통해 기기와 클라우드 간에 데이터 전송
- 대안
사용자가 장기 실행 데이터 업로드 또는 다운로드 작업을 시작할 수 있도록 사용자가 시작한 데이터 전송 작업을 만듭니다.
다운로드 관리자 API를 사용하여 URI에서 데이터를 다운로드합니다.
BackupManager
를 사용하여 데이터를 백업하거나 복원합니다.다른 사용 사례의 경우 WorkManager를 고려하세요.
Health
- Foreground service type to declare in manifest under
android:foregroundServiceType
health
- Permission to declare in your manifest
FOREGROUND_SERVICE_HEALTH
- Constant to pass to
startForeground()
FOREGROUND_SERVICE_TYPE_HEALTH
- Runtime prerequisites
At least one of the following conditions must be true:
Declare the
HIGH_SAMPLING_RATE_SENSORS
permission in your manifest.Request and be granted at least one of the following runtime permissions:
Note: The
BODY_SENSORS
runtime permission is subject to while-in-use restrictions. For this reason, you cannot create ahealth
foreground service that uses body sensors while your app is in the background, with a few exceptions. For more information, see Restrictions on starting foreground services that need while-in-use permissions.- Description
Any long-running use cases to support apps in the fitness category such as exercise trackers.
위치
- 매니페스트에서 선언할 포그라운드 서비스 유형
android:foregroundServiceType
location
- 매니페스트에서 선언할 권한
FOREGROUND_SERVICE_LOCATION
startForeground()
에 전달할 상수FOREGROUND_SERVICE_TYPE_LOCATION
- 런타임 기본 요건
다음 런타임 권한 중 하나 이상을 요청하고 부여받아야 합니다.
참고: 위치 런타임 권한에는 사용 중 제한사항이 적용됩니다. 이러한 이유로 몇 가지 예외를 제외하고 앱이 백그라운드에 있는 동안에는
location
포그라운드 서비스를 만들 수 없습니다. 자세한 내용은 사용 중 권한이 필요한 포그라운드 서비스 시작 제한사항을 참고하세요.- 설명
탐색 및 위치 공유와 같이 위치 액세스가 필요한 장기 실행 사용 사례
- 대안
사용자가 특정 위치에 도달할 때 앱을 트리거해야 한다면 지오펜싱 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.
미디어 프로젝션
- 매니페스트에서 선언할 포그라운드 서비스 유형
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
포그라운드 서비스를 만들 수 없습니다. 자세한 내용은 사용 중 권한이 필요한 포그라운드 서비스 시작 제한사항을 참고하세요.- 설명
음성 녹음기 또는 통신 앱과 같이 백그라운드에서 마이크 캡처를 계속합니다.
전화 통화
- 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.
원격 메시지
- 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.
짧은 서비스
- 매니페스트에서 선언할 포그라운드 서비스 유형
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
유형 선언을 무시합니다. 하지만 서비스는 여전히 선언된 다른 유형의 기본 요건을 준수해야 합니다. 자세한 내용은 포그라운드 서비스 문서를 참고하세요.
특수 용도
- Foreground service type to declare in manifest under
android:foregroundServiceType
specialUse
- 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_USE
foreground 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 thespecialUse
type.<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에서 포그라운드 서비스 유형을 선언하는 방법에 관한 자세한 내용은 포그라운드 서비스 및 전체 화면 인텐트 요구사항 이해를 참고하세요.