포그라운드 서비스 유형

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 CAMERA runtime 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: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:

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.

데이터 동기화

Foreground service type to declare in manifest under
android:foregroundServiceType
dataSync
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:foregroundServiceType
health
매니페스트에서 선언할 권한
FOREGROUND_SERVICE_HEALTH
startForeground()에 전달할 상수
FOREGROUND_SERVICE_TYPE_HEALTH
런타임 기본 요건

다음 조건 중 하나 이상에 해당해야 합니다.

설명

운동 추적기 등 피트니스 카테고리의 앱을 지원하기 위한 장기 실행 사용 사례입니다.

위치

매니페스트에서 선언할 포그라운드 서비스 유형
android:foregroundServiceType
location
매니페스트에서 선언할 권한
FOREGROUND_SERVICE_LOCATION
startForeground()에 전달할 상수
FOREGROUND_SERVICE_TYPE_LOCATION
런타임 기본 요건

사용자는 위치 서비스를 사용 설정해야 하며 앱에 다음 런타임 권한 중 하나 이상이 부여되어야 합니다.

설명

탐색 및 위치 공유와 같이 위치 액세스가 필요한 장기 실행 사용 사례

대안

사용자가 특정 위치에 도달할 때 앱이 트리거되어야 하는 경우 대신 geofence API를 사용하는 것이 좋습니다.

미디어

매니페스트에서
android:foregroundServiceType
mediaPlayback
매니페스트에서 선언할 권한
FOREGROUND_SERVICE_MEDIA_PLAYBACK
startForeground()에 전달할 상수
FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK
런타임 기본 요건
없음
설명

백그라운드에서 오디오 또는 동영상을 계속 재생합니다. Android TV에서 디지털 동영상 녹화 (DVR) 기능을 지원합니다.

대안

PIP 동영상을 표시하는 경우 PIP 모드를 사용합니다.

미디어 처리 중

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:

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 call Service.stopSelf(). If the service does not call Service.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:foregroundServiceType
mediaProjection
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 MediaProjection APIs. This content doesn't have to be exclusively media content.

Alternatives

To stream media to another device, use the 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.

전화 통화

매니페스트에서
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.

짧은 서비스

매니페스트에서 선언할 포그라운드 서비스 유형
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 the specialUse 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>

시스템 제외됨

Foreground service type to declare in manifest under
android:foregroundServiceType
systemExempted
Permission to declare in your manifest
FOREGROUND_SERVICE_SYSTEM_EXEMPTED
Constant to pass to startForeground()
FOREGROUND_SERVICE_TYPE_SYSTEM_EXEMPTED
Runtime prerequisites
None
Description

Reserved for system applications and specific system integrations, to continue to use foreground services.

To use this type, an app must meet at least one of the following criteria:

포그라운드 서비스 유형 사용에 관한 Google Play 정책 시행

앱이 Android 14 이상을 타겟팅하는 경우 Play Console의 앱 콘텐츠 페이지 (정책 > 앱 콘텐츠)에서 앱의 포그라운드 서비스 유형을 선언해야 합니다. Play Console에서 포그라운드 서비스 유형을 선언하는 방법에 관한 자세한 내용은 포그라운드 서비스 및 전체 화면 인텐트 요구사항 이해하기를 참고하세요.