포그라운드 서비스 유형은 필수 항목임

개발자가 사용자 대상 포그라운드 서비스를 더 잘 정의하도록 돕기 위해 Android 10에서는 <service> 요소 내에 android:foregroundServiceType 속성을 도입했습니다.

앱이 Android 14를 타겟팅하는 경우 적절한 포그라운드 서비스 유형을 지정해야 합니다. 이전 버전의 Android에서와 마찬가지로 여러 유형을 결합할 수 있습니다. 이 목록에는 선택할 수 있는 포그라운드 서비스 유형이 표시됩니다.

앱의 사용 사례가 이러한 유형과 연결되어 있지 않으면 WorkManager 또는 사용자가 시작한 데이터 전송 작업을 사용하도록 로직을 이전하는 것이 좋습니다.

health, remoteMessaging, shortService, specialUsesystemExempted 유형은 Android 14에 새로 도입되었습니다.

다음 코드 스니펫은 매니페스트에서 포그라운드 서비스 유형을 선언하는 예를 보여줍니다.

<manifest ...>
  <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
  <uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
    <application ...>
      <service
          android:name=".MyMediaPlaybackService"
          android:foregroundServiceType="mediaPlayback"
          android:exported="false">
      </service>
    </application>
</manifest>

Android 14를 타겟팅하는 앱이 매니페스트에서 특정 서비스의 유형을 정의하지 않으면 시스템은 해당 서비스의 startForeground() 호출 시 MissingForegroundServiceTypeException을 발생시킵니다.

포그라운드 서비스 유형을 사용할 새로운 권한 선언

Android 14를 타겟팅하는 앱이 포그라운드 서비스를 사용하는 경우 앱은 Android 14에 도입된 포그라운드 서비스 유형에 따라 특정 권한을 선언해야 합니다. 이러한 권한은 이 페이지의 각 포그라운드 서비스 유형의 의도된 사용 사례 및 시행 섹션에 있는 '매니페스트 파일에서 선언해야 하는 권한' 섹션에 표시됩니다.

모든 권한은 일반 권한으로 정의되며 기본적으로 부여됩니다. 사용자는 이러한 권한을 취소할 수 없습니다.

런타임에 포그라운드 서비스 유형 포함

포그라운드 서비스를 시작하는 애플리케이션에 관한 권장사항은 포그라운드 서비스 유형의 비트 정수를 전달하는 startForeground()ServiceCompat 버전 (androidx-core 1.12 이상에서 사용 가능)을 사용하는 것입니다. 하나 이상의 유형 값을 전달하도록 선택할 수 있습니다.

일반적으로 특정 사용 사례에 필요한 유형만 선언해야 합니다. 이렇게 하면 각 포그라운드 서비스 유형에 관한 시스템의 기대치를 더 쉽게 충족할 수 있습니다. 포그라운드 서비스가 여러 유형으로 시작된 경우 포그라운드 서비스는 모든 유형의 플랫폼 시행 요구사항을 준수해야 합니다.

ServiceCompat.startForeground(0, notification, FOREGROUND_SERVICE_TYPE_LOCATION)

포그라운드 서비스 유형이 호출에서 지정되지 않으면 유형이 매니페스트에 정의된 값으로 기본 설정됩니다. 매니페스트에서 서비스 유형을 지정하지 않으면 시스템에서 MissingForegroundServiceTypeException을 발생시킵니다.

포그라운드 서비스를 실행한 후 포그라운드 서비스에 새 권한이 필요한 경우 startForeground()를 다시 호출하고 새 서비스 유형을 추가해야 합니다. 예를 들어 피트니스 앱이 항상 location 정보가 필요하지만 media 권한이 필요하지 않을 수도 있는 달리기 추적 서비스를 실행한다고 가정해 보겠습니다. 매니페스트에서 locationmediaPlayback를 모두 선언해야 합니다. 사용자가 달리기를 시작하고 위치만 추적하려는 경우 앱은 startForeground()를 호출하고 location 서비스 유형만 전달해야 합니다. 그런 다음 사용자가 오디오 재생을 시작하려면 startForeground()를 다시 호출하고 location|mediaPlayback를 전달합니다.

시스템 런타임 검사

시스템은 포그라운드 서비스 유형의 올바른 사용을 확인하고, 앱이 적절한 런타임 권한을 요청했거나 필수 API를 사용하는지 확인합니다. 예를 들어 시스템은 포그라운드 서비스 유형 FOREGROUND_SERVICE_TYPE_LOCATION 유형을 사용하는 앱이 ACCESS_COARSE_LOCATION 또는 ACCESS_FINE_LOCATION을 요청할 것으로 예상합니다.

즉, 앱은 사용자에게 권한을 요청하고 포그라운드 서비스를 시작할 때 매우 구체적인 작업 순서를 따라야 합니다. 앱이 startForeground()를 호출하려고 하기 전에 권한을 요청하고 부여받아야 합니다. 포그라운드 서비스가 시작된 후 적절한 권한을 요청하는 앱은 이 작업 순서를 변경하고, 포그라운드 서비스를 시작하기 전에 권한을 요청해야 합니다.

플랫폼 시행의 세부정보는 이 페이지에 있는 각 포그라운드 서비스 유형의 의도된 사용 사례 및 시행에서 '런타임 요구사항' 섹션에 나와 있습니다.

각 포그라운드 서비스 유형의 의도된 사용 사례 및 시행

In order to use a given foreground service type, you must declare a particular permission in your manifest file, you must fulfill specific runtime requirements, and your app must fulfill one of the intended sets of use cases for that type. The following sections explain the permission that you must declare, the runtime prerequisites, and the intended use cases for each type.

카메라

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
런타임 기본 요건

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

설명

블루투스, 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
런타임 기본 요건

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

참고: BODY_SENSORS 및 센서 기반 읽기 런타임 권한에는 사용 중 제한사항이 적용됩니다. 따라서 BODY_SENSORS_BACKGROUND(API 수준 33~35) 또는 READ_HEALTH_DATA_IN_BACKGROUND (API 수준 36 이상) 권한이 부여되지 않은 한 앱이 백그라운드에 있는 동안 신체 센서를 사용하는 health 포그라운드 서비스를 만들 수 없습니다. 자세한 내용은 사용 중 권한이 필요한 포그라운드 서비스 시작에 관한 제한사항을 참고하세요.

설명

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

위치

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

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

참고: 사용자가 위치 서비스를 사용 설정했는지, 런타임 권한에 대한 액세스 권한을 부여했는지 확인하려면 PermissionChecker#checkSelfPermission()를 사용하세요.

참고: 위치 런타임 권한에는 사용 중 제한사항이 적용됩니다. 따라서 ACCESS_BACKGROUND_LOCATION 런타임 권한이 부여되지 않은 한 앱이 백그라운드에 있는 동안 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
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.

마이크

매니페스트에서 선언할 포그라운드 서비스 유형
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를 사용하여 통화를 선별하는 것이 좋습니다.

원격 메시지

매니페스트에서 선언할 포그라운드 서비스 유형
android:foregroundServiceType
remoteMessaging
매니페스트에서 선언할 권한
FOREGROUND_SERVICE_REMOTE_MESSAGING
startForeground()에 전달할 상수
FOREGROUND_SERVICE_TYPE_REMOTE_MESSAGING
런타임 기본 요건
없음
설명
문자 메시지를 한 기기에서 다른 기기로 전송합니다. 사용자가 기기를 전환할 때 사용자의 메시지 작업의 연속성을 지원합니다.

짧은 서비스

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 call Service.stopSelf() or Service.stopForeground() before the timeout occurs. Otherwise, the new Service.onTimeout() is called, giving apps a brief opportunity to call stopSelf() or stopForeground() 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 mentions FOREGROUND_SERVICE_TYPE_SHORT_SERVICE. For these reasons, it's considered best practice to implement the Service.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 the Service.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 the FOREGROUND_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 a ForegroundServiceStartNotAllowedException.

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 the shortService 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>

시스템 제외됨

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:

  • Device is in demo mode state
  • App is a Device Owner
  • App is a Profiler Owner
  • Safety Apps that have the ROLE_EMERGENCY role
  • Device Admin apps
  • Apps holding SCHEDULE_EXACT_ALARM or USE_EXACT_ALARM permission and are using Foreground Service to continue alarms in the background, including haptics-only alarms.
  • VPN apps (configured using Settings > Network & Internet > VPN)

    Otherwise, declaring this type causes the system to throw a ForegroundServiceTypeNotAllowedException.

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

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