Added in API level 1

ServiceInfo

open class ServiceInfo : ComponentInfo, Parcelable
kotlin.Any
   ↳ android.content.pm.PackageItemInfo
   ↳ android.content.pm.ComponentInfo
   ↳ android.content.pm.ServiceInfo

Information you can retrieve about a particular application service. This corresponds to information collected from the AndroidManifest.xml's <service> tags.

Summary

Constants
static Int

Bit in flags: If set, and this is an android.R.attr#isolatedProcess service, the service is allowed to be bound in a shared isolated process with other isolated services.

static Int

Bit in flags: If set, the service can be bound and run in the calling application's package, rather than the package in which it is declared.

static Int

Bit in flags: If set, the service will run in its own isolated process.

static Int

Bit in flags: If set, a single instance of the service will run for all users on the device.

static Int

Bit in flags: If set, the service will automatically be stopped by the system if the user removes a task that is rooted in one of the application's activities.

static Int

Bit in flags: If set, the service (which must be isolated) will be spawned from an Application Zygote, instead of the regular Zygote.

static Int

Constant corresponding to camera in the android.R.attr#foregroundServiceType attribute.

static Int

Constant corresponding to connectedDevice in the android.R.attr#foregroundServiceType attribute.

static Int

Constant corresponding to dataSync in the android.R.attr#foregroundServiceType attribute.

static Int

Constant corresponding to health in the android.R.attr#foregroundServiceType attribute.

static Int

Constant corresponding to location in the android.R.attr#foregroundServiceType attribute.

static Int

A special value indicates to use all types set in manifest file.

static Int

Constant corresponding to mediaPlayback in the android.R.attr#foregroundServiceType attribute.

static Int

Constant corresponding to mediaProjection in the foregroundServiceType attribute.

static Int

Constant corresponding to microphone in the android.R.attr#foregroundServiceType attribute.

static Int

The default foreground service type if not been set in manifest file.

static Int

Constant corresponding to phoneCall in the android.R.attr#foregroundServiceType attribute.

static Int

Constant corresponding to remoteMessaging in the android.R.attr#foregroundServiceType attribute.

static Int

A foreground service type for "short-lived" services, which corresponds to shortService in the android.R.attr#foregroundServiceType attribute in the manifest.

static Int

Constant corresponding to specialUse in the android.R.attr#foregroundServiceType attribute.

static Int

Constant corresponding to systemExempted in the android.R.attr#foregroundServiceType attribute.

Inherited constants
Public constructors

Public methods
open Int

open Unit
dump(pw: Printer!, prefix: String!)

open Int

Return foreground service type specified in the manifest.

open String

open Unit
writeToParcel(dest: Parcel, parcelableFlags: Int)

Inherited functions
Properties
static Parcelable.Creator<ServiceInfo!>

Int

Options that have been set in the service declaration in the manifest.

String!

Optional name of a permission required to be able to access this Service.

Inherited properties

Constants

FLAG_ALLOW_SHARED_ISOLATED_PROCESS

static val FLAG_ALLOW_SHARED_ISOLATED_PROCESS: Int

Bit in flags: If set, and this is an android.R.attr#isolatedProcess service, the service is allowed to be bound in a shared isolated process with other isolated services. Note that these other isolated services can also belong to other apps from different vendors. Shared isolated processes are created when using the ) during service binding.

Value: 16

FLAG_EXTERNAL_SERVICE

Added in API level 24
static val FLAG_EXTERNAL_SERVICE: Int

Bit in flags: If set, the service can be bound and run in the calling application's package, rather than the package in which it is declared. Set from android.R.attr#externalService attribute.

Value: 4

FLAG_ISOLATED_PROCESS

Added in API level 16
static val FLAG_ISOLATED_PROCESS: Int

Bit in flags: If set, the service will run in its own isolated process. Set from the android.R.attr#isolatedProcess attribute.

Value: 2

FLAG_SINGLE_USER

Added in API level 17
static val FLAG_SINGLE_USER: Int

Bit in flags: If set, a single instance of the service will run for all users on the device. Set from the android.R.attr#singleUser attribute.

Value: 1073741824

FLAG_STOP_WITH_TASK

Added in API level 14
static val FLAG_STOP_WITH_TASK: Int

Bit in flags: If set, the service will automatically be stopped by the system if the user removes a task that is rooted in one of the application's activities. Set from the android.R.attr#stopWithTask attribute.

Value: 1

FLAG_USE_APP_ZYGOTE

Added in API level 29
static val FLAG_USE_APP_ZYGOTE: Int

Bit in flags: If set, the service (which must be isolated) will be spawned from an Application Zygote, instead of the regular Zygote. The Application Zygote will pre-initialize the application's class loader, and call a static callback into the application to allow it to perform application-specific preloads (such as loading a shared library). Therefore, spawning from the Application Zygote will typically reduce the service launch time and reduce its memory usage. The downside of using this flag is that you will have an additional process (the app zygote itself) that is taking up memory. Whether actual memory usage is improved therefore strongly depends on the number of isolated services that an application starts, and how much memory those services save by preloading. Therefore, it is recommended to measure memory usage under typical workloads to determine whether it makes sense to use this flag.

Value: 8

FOREGROUND_SERVICE_TYPE_CAMERA

Added in API level 30
static val FOREGROUND_SERVICE_TYPE_CAMERA: Int

Constant corresponding to camera in the android.R.attr#foregroundServiceType attribute. Use the camera device or record video. For apps with targetSdkVersion android.os.Build.VERSION_CODES#R and above, a foreground service will not be able to access the camera if this type is not specified in the manifest and in android.app.Service#startForeground(int, android.app.Notification, int).

Starting foreground service with this type from apps targeting API level android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE and later, will require permission android.Manifest.permission#FOREGROUND_SERVICE_CAMERA and android.Manifest.permission#CAMERA.

Value: 64

FOREGROUND_SERVICE_TYPE_CONNECTED_DEVICE

Added in API level 29
static val FOREGROUND_SERVICE_TYPE_CONNECTED_DEVICE: Int

Constant corresponding to connectedDevice in the android.R.attr#foregroundServiceType attribute. Auto, bluetooth, TV or other devices connection, monitoring and interaction.

Starting foreground service with this type from apps targeting API level android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE and later, will require permission android.Manifest.permission#FOREGROUND_SERVICE_CONNECTED_DEVICE and one of the following permissions: android.Manifest.permission#BLUETOOTH_ADVERTISE, android.Manifest.permission#BLUETOOTH_CONNECT, android.Manifest.permission#BLUETOOTH_SCAN, android.Manifest.permission#CHANGE_NETWORK_STATE, android.Manifest.permission#CHANGE_WIFI_STATE, android.Manifest.permission#CHANGE_WIFI_MULTICAST_STATE, android.Manifest.permission#NFC, android.Manifest.permission#TRANSMIT_IR, android.Manifest.permission#UWB_RANGING, or has been granted the access to one of the attached USB devices/accessories.

Value: 16

FOREGROUND_SERVICE_TYPE_DATA_SYNC

Added in API level 29
static val FOREGROUND_SERVICE_TYPE_DATA_SYNC: Int

Constant corresponding to dataSync in the android.R.attr#foregroundServiceType attribute. Data(photo, file, account) upload/download, backup/restore, import/export, fetch, transfer over network between device and cloud.

Value: 1

FOREGROUND_SERVICE_TYPE_HEALTH

Added in API level 34
static val FOREGROUND_SERVICE_TYPE_HEALTH: Int

Constant corresponding to health in the android.R.attr#foregroundServiceType attribute. Health, wellness and fitness.

The caller app is required to have the permissions android.Manifest.permission#FOREGROUND_SERVICE_HEALTH and one of the following permissions: android.Manifest.permission#ACTIVITY_RECOGNITION, android.Manifest.permission#BODY_SENSORS, android.Manifest.permission#HIGH_SAMPLING_RATE_SENSORS.
Requires android.Manifest.permission#ACTIVITY_RECOGNITION or android.Manifest.permission#BODY_SENSORS or android.Manifest.permission#HIGH_SAMPLING_RATE_SENSORS

Value: 256

FOREGROUND_SERVICE_TYPE_LOCATION

Added in API level 29
static val FOREGROUND_SERVICE_TYPE_LOCATION: Int

Constant corresponding to location in the android.R.attr#foregroundServiceType attribute. GPS, map, navigation location update.

Starting foreground service with this type from apps targeting API level android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE and later, will require permission android.Manifest.permission#FOREGROUND_SERVICE_LOCATION and one of the following permissions: android.Manifest.permission#ACCESS_COARSE_LOCATION, android.Manifest.permission#ACCESS_FINE_LOCATION.

Value: 8

FOREGROUND_SERVICE_TYPE_MANIFEST

Added in API level 29
static val FOREGROUND_SERVICE_TYPE_MANIFEST: Int

A special value indicates to use all types set in manifest file.

Value: -1

FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK

Added in API level 29
static val FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK: Int

Constant corresponding to mediaPlayback in the android.R.attr#foregroundServiceType attribute. Music, video, news or other media playback.

Starting foreground service with this type from apps targeting API level android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE and later, will require permission android.Manifest.permission#FOREGROUND_SERVICE_MEDIA_PLAYBACK.

Value: 2

FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION

Added in API level 29
static val FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION: Int

Constant corresponding to mediaProjection in the foregroundServiceType attribute.

To capture through android.media.projection.MediaProjection, an app must start a foreground service with the type corresponding to this constant. This type should only be used for android.media.projection.MediaProjection. Capturing screen contents via createVirtualDisplay conveniently allows recording, presenting screen contents into a meeting, taking screenshots, or several other scenarios.

Starting foreground service with this type from apps targeting API level android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE and later, will require permission android.Manifest.permission#FOREGROUND_SERVICE_MEDIA_PROJECTION, and the user must have allowed the screen capture request from this app.

Value: 32

FOREGROUND_SERVICE_TYPE_MICROPHONE

Added in API level 30
static val FOREGROUND_SERVICE_TYPE_MICROPHONE: Int

Constant corresponding to microphone in the android.R.attr#foregroundServiceType attribute. Use the microphone device or record audio. For apps with targetSdkVersion android.os.Build.VERSION_CODES#R and above, a foreground service will not be able to access the microphone if this type is not specified in the manifest and in android.app.Service#startForeground(int, android.app.Notification, int).

Starting foreground service with this type from apps targeting API level android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE and later, will require permission android.Manifest.permission#FOREGROUND_SERVICE_MICROPHONE and one of the following permissions: android.Manifest.permission#CAPTURE_AUDIO_OUTPUT, android.Manifest.permission#RECORD_AUDIO.

Value: 128

FOREGROUND_SERVICE_TYPE_NONE

Added in API level 29
Deprecated in API level 34
static val FOREGROUND_SERVICE_TYPE_NONE: Int

Deprecated: Do not use.

The default foreground service type if not been set in manifest file.

Apps targeting API level android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE and later should NOT use this type, calling android.app.Service#startForeground(int, android.app.Notification, int) with this type will get a android.app.InvalidForegroundServiceTypeException.

Value: 0

FOREGROUND_SERVICE_TYPE_PHONE_CALL

Added in API level 29
static val FOREGROUND_SERVICE_TYPE_PHONE_CALL: Int

Constant corresponding to phoneCall in the android.R.attr#foregroundServiceType attribute. Ongoing operations related to phone calls, video conferencing, or similar interactive communication.

Starting foreground service with this type from apps targeting API level android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE and later, will require permission android.Manifest.permission#FOREGROUND_SERVICE_PHONE_CALL and android.Manifest.permission#MANAGE_OWN_CALLS or holding the default dialer role.

Value: 4

FOREGROUND_SERVICE_TYPE_REMOTE_MESSAGING

Added in API level 34
static val FOREGROUND_SERVICE_TYPE_REMOTE_MESSAGING: Int

Constant corresponding to remoteMessaging in the android.R.attr#foregroundServiceType attribute. Messaging use cases which host local server to relay messages across devices.
Requires android.Manifest.permission#FOREGROUND_SERVICE_REMOTE_MESSAGING

Value: 512

FOREGROUND_SERVICE_TYPE_SHORT_SERVICE

Added in API level 34
static val FOREGROUND_SERVICE_TYPE_SHORT_SERVICE: Int

A foreground service type for "short-lived" services, which corresponds to shortService in the android.R.attr#foregroundServiceType attribute in the manifest.

Unlike other foreground service types, this type is not associated with a specific use case, and it will not require any special permissions (besides android.Manifest.permission#FOREGROUND_SERVICE). However, this type has the following restrictions.

Also note, even though android.content.pm.ServiceInfo#FOREGROUND_SERVICE_TYPE_SHORT_SERVICE was added on Android version android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE, it can be also used on on prior android versions (just like other new foreground service types can be used). However, because android.app.Service#onTimeout(int) did not exist on prior versions, it will never called on such versions. Because of this, developers must make sure to stop the foreground service even if android.app.Service#onTimeout(int) is not called on such versions.

Value: 2048

FOREGROUND_SERVICE_TYPE_SPECIAL_USE

Added in API level 34
static val FOREGROUND_SERVICE_TYPE_SPECIAL_USE: Int

Constant corresponding to specialUse in the android.R.attr#foregroundServiceType attribute. Use cases that can't be categorized into any other foreground service types, but also can't use android.app.job.JobInfo.Builder APIs.

The use of this foreground service type may be restricted. Additionally, apps must declare a service-level <property> in AndroidManifest.xml as a hint of what the exact use case here is. Here is an example:

<uses-permission
       android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE"
   />
   <service
       android:name=".MySpecialForegroundService"
       android:foregroundServiceType="specialUse">
       <property
           android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
           android:value="foo"
       />
  </service>
  
In a future release of Android, if the above foreground service type foo is supported by the platform, to offer the backward compatibility, the app could specify the android:maxSdkVersion attribute in the <uses-permission> section, and also add the foreground service type foo into the android:foregroundServiceType, therefore the same app could be installed in both platforms.
<uses-permission
       android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE"
       android:maxSdkVersion="last_sdk_version_without_type_foo"
   />
   <service
       android:name=".MySpecialForegroundService"
       android:foregroundServiceType="specialUse|foo">
       <property
           android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
           android:value="foo"
       />
  </service>
  

Requires android.Manifest.permission#FOREGROUND_SERVICE_SPECIAL_USE
Value: 1073741824

FOREGROUND_SERVICE_TYPE_SYSTEM_EXEMPTED

Added in API level 34
static val FOREGROUND_SERVICE_TYPE_SYSTEM_EXEMPTED: Int

Constant corresponding to systemExempted in the android.R.attr#foregroundServiceType attribute. The system exempted foreground service use cases.

Note, apps are allowed to use this type only in the following cases:


Requires android.Manifest.permission#FOREGROUND_SERVICE_SYSTEM_EXEMPTED
Value: 1024

Public constructors

ServiceInfo

Added in API level 1
ServiceInfo()

ServiceInfo

Added in API level 1
ServiceInfo(orig: ServiceInfo!)

Public methods

describeContents

Added in API level 1
open fun describeContents(): Int
Return
Int a bitmask indicating the set of special object types marshaled by this Parcelable object instance. Value is either 0 or android.os.Parcelable#CONTENTS_FILE_DESCRIPTOR

dump

Added in API level 5
open fun dump(
    pw: Printer!,
    prefix: String!
): Unit

toString

Added in API level 1
open fun toString(): String
Return
String a string representation of the object.

writeToParcel

Added in API level 1
open fun writeToParcel(
    dest: Parcel,
    parcelableFlags: Int
): Unit
Parameters
dest Parcel: The Parcel in which the object should be written. This value cannot be null.
flags Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE. Value is either 0 or a combination of android.os.Parcelable#PARCELABLE_WRITE_RETURN_VALUE, and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES

Properties

CREATOR

Added in API level 1
static val CREATOR: Parcelable.Creator<ServiceInfo!>

flags

Added in API level 14
var flags: Int

Options that have been set in the service declaration in the manifest. These include: FLAG_STOP_WITH_TASK, FLAG_ISOLATED_PROCESS, FLAG_SINGLE_USER.

permission

Added in API level 1
var permission: String!

Optional name of a permission required to be able to access this Service. From the "permission" attribute.