Context

abstract class Context
kotlin.Any
   ↳ android.content.Context

Interface to global information about an application environment. This is an abstract class whose implementation is provided by the Android system. It allows access to application-specific resources and classes, as well as up-calls for application-level operations such as launching activities, broadcasting and receiving intents, etc.

Summary

Constants
static String

Use with getSystemService(java.lang.String) to retrieve a android.view.accessibility.AccessibilityManager for giving the user feedback for UI events through the registered event listeners.

static String

Use with getSystemService(java.lang.String) to retrieve a android.accounts.AccountManager for receiving intents at a time of your choosing.

static String

Use with getSystemService(java.lang.String) to retrieve a android.app.ActivityManager for interacting with the global system state.

static String

Use with getSystemService(java.lang.String) to retrieve a android.app.AlarmManager for receiving intents at a time of your choosing.

static String

Use with getSystemService(java.lang.String) to retrieve a android.appwidget.AppWidgetManager for accessing AppWidgets.

static String

Use with getSystemService(java.lang.String) to retrieve a android.app.AppOpsManager for tracking application operations on the device.

static String

Use with getSystemService(java.lang.String) to retrieve a android.media.AudioManager for handling management of volume, ringer modes and audio routing.

static String

Use with getSystemService(java.lang.String) to retrieve a android.os.BatteryManager for managing battery state.

static Int

Flag for bindService: indicates that the client application binding to this service considers the service to be more important than the app itself.

static Int

Flag for bindService: If binding from an activity, allow the target service's process importance to be raised based on whether the activity is visible to the user, regardless whether another flag is used to reduce the amount that the client process's overall importance is used to impact it.

static Int

Flag for bindService: allow the process hosting the bound service to go through its normal memory management.

static Int

Flag for bindService: automatically create the service as long as the binding exists.

static Int

Flag for bindService: include debugging help for mismatched calls to unbind.

static Int

Flag for bindService: The service being bound is an isolated, external service.

static Int

Flag for bindService: this service is very important to the client, so should be brought to the foreground process level when the client is.

static Int

Flag for bindService: don't allow this binding to raise the target service's process to the foreground scheduling priority.

static Int

Flag for bindService: don't impact the scheduling or memory management priority of the target service's hosting process.

static String

Use with getSystemService(java.lang.String) to retrieve a android.hardware.biometrics.BiometricManager for handling management of face authentication.

static String

Use with getSystemService(java.lang.String) to retrieve a android.bluetooth.BluetoothManager for using Bluetooth.

static String

Use with getSystemService(java.lang.String) to retrieve a android.hardware.camera2.CameraManager for interacting with camera devices.

static String

Use with getSystemService(java.lang.String) to retrieve a android.view.accessibility.CaptioningManager for obtaining captioning properties and listening for changes in captioning preferences.

static String

Use with getSystemService(java.lang.String) to retrieve a android.telephony.CarrierConfigManager for reading carrier configuration values.

static String

Use with getSystemService(java.lang.String) to retrieve a android.content.ClipboardManager for accessing and modifying the contents of the global clipboard.

static String

Use with getSystemService(java.lang.String) to retrieve a android.companion.CompanionDeviceManager for managing companion devices

static String

Use with getSystemService(java.lang.String) to retrieve a for handling management of network connections.

static String

Use with getSystemService(java.lang.String) to retrieve a android.hardware.ConsumerIrManager for transmitting infrared signals from the device.

static Int

Flag for use with createPackageContext: ignore any security restrictions on the Context being requested, allowing it to always be loaded.

static Int

Flag for use with createPackageContext: include the application code with the context.

static Int

Flag for use with createPackageContext: a restricted context may disable specific features.

static String

Use with getSystemService(java.lang.String) to retrieve a android.content.pm.CrossProfileApps for cross profile operations.

static String

Use with getSystemService(java.lang.String) to retrieve a android.app.admin.DevicePolicyManager for working with global device policy management.

static String

Use with getSystemService(java.lang.String) to retrieve a android.hardware.display.DisplayManager for interacting with display devices.

static String

Use with getSystemService(java.lang.String) to retrieve a android.app.DownloadManager for requesting HTTP downloads.

static String

Use with getSystemService(java.lang.String) to retrieve a android.os.DropBoxManager instance for recording diagnostic logs.

static String

Use with getSystemService(java.lang.String) to retrieve a android.telephony.euicc.EuiccManager to manage the device eUICC (embedded SIM).

static String

Use with getSystemService(java.lang.String) to retrieve a android.hardware.fingerprint.FingerprintManager for handling management of fingerprints.

static String

Use with getSystemService(java.lang.String) to retrieve a android.os.HardwarePropertiesManager for accessing the hardware properties service.

static String

Use with getSystemService(java.lang.String) to retrieve a android.view.inputmethod.InputMethodManager for accessing input methods.

static String

Use with getSystemService(java.lang.String) to retrieve a android.hardware.input.InputManager for interacting with input devices.

static String

Use with getSystemService(java.lang.String) to retrieve a android.net.IpSecManager for encrypting Sockets or Networks with IPSec.

static String

Use with getSystemService(java.lang.String) to retrieve a instance for managing occasional background tasks.

static String

Use with getSystemService(java.lang.String) to retrieve a android.app.KeyguardManager for controlling keyguard.

static String

Use with getSystemService(java.lang.String) to retrieve a android.content.pm.LauncherApps for querying and monitoring launchable apps across profiles of a user.

static String

Use with getSystemService(java.lang.String) to retrieve a android.view.LayoutInflater for inflating layout resources in this context.

static String

Use with getSystemService(java.lang.String) to retrieve a for controlling location updates.

static String

Use with getSystemService(java.lang.String) to retrieve a instance for managing media projection sessions.

static String

Use with getSystemService to retrieve a android.media.MediaRouter for controlling and managing routing of media.

static String

Use with getSystemService(java.lang.String) to retrieve a android.media.session.MediaSessionManager for managing media Sessions.

static String

Use with getSystemService(java.lang.String) to retrieve a android.media.midi.MidiManager for accessing the MIDI service.

static Int

File creation mode: for use with openFileOutput, if the file already exists then write data to the end of the existing file instead of erasing it.

static Int

Database open flag: when set, the database is opened with write-ahead logging enabled by default.

static Int

SharedPreference loading flag: when set, the file on disk will be checked for modification even if the shared preferences instance is already loaded in this process.

static Int

Database open flag: when set, the database is opened without support for localized collators.

static Int

File creation mode: the default mode, where the created file can only be accessed by the calling application (or all applications sharing the same user ID).

static Int

File creation mode: allow all other applications to have read access to the created file.

static Int

File creation mode: allow all other applications to have write access to the created file.

static String

Use with getSystemService(java.lang.String) to retrieve a for querying network usage stats.

static String

Use with getSystemService(java.lang.String) to retrieve a android.nfc.NfcManager for using NFC.

static String

Use with getSystemService(java.lang.String) to retrieve a android.app.NotificationManager for informing the user of background events.

static String

Use with getSystemService(java.lang.String) to retrieve a for handling management of network service discovery

static String

Use with getSystemService(java.lang.String) to retrieve a android.os.PowerManager for controlling power management, including "wake locks," which let you keep the device on while you're running long tasks.

static String

android.print.PrintManager for printing and managing printers and print tasks.

static Int

Flag for registerReceiver: The receiver can receive broadcasts from Instant Apps.

static String

Use with getSystemService(java.lang.String) to retrieve a android.content.RestrictionsManager for retrieving application restrictions and requesting permissions for restricted operations.

static String

Use with getSystemService(java.lang.String) to retrieve a android.app.role.RoleManager for managing roles.

static String

Use with getSystemService(java.lang.String) to retrieve a for handling searches.

static String

Use with getSystemService(java.lang.String) to retrieve a for accessing sensors.

static String

Use with getSystemService(java.lang.String) to retrieve a android.content.pm.ShortcutManager for accessing the launcher shortcut service.

static String

Use with getSystemService(java.lang.String) to retrieve a for accessing system storage functions.

static String

Use with getSystemService(java.lang.String) to retrieve a for accessing system storage statistics.

static String

Use with getSystemService(java.lang.String) to retrieve a android.os.health.SystemHealthManager for accessing system health (battery, power, memory, etc) metrics.

static String

Use with getSystemService(java.lang.String) to retrieve a android.telecom.TelecomManager to manage telecom-related features of the device.

static String

Use with getSystemService(java.lang.String) to retrieve a android.telephony.TelephonyManager for handling management the telephony features of the device.

static String

Use with getSystemService(java.lang.String) to retrieve a android.telephony.SubscriptionManager for handling management the telephony subscriptions of the device.

static String

Use with getSystemService(java.lang.String) to retrieve a TextClassificationManager for text classification services.

static String

Use with getSystemService(java.lang.String) to retrieve a android.view.textservice.TextServicesManager for accessing text services.

static String

Use with getSystemService(java.lang.String) to retrieve a android.media.tv.TvInputManager for interacting with TV inputs on the device.

static String

Use with getSystemService(java.lang.String) to retrieve a android.app.UiModeManager for controlling UI modes.

static String

Use with getSystemService(java.lang.String) to retrieve a for querying device usage stats.

static String

Use with getSystemService(java.lang.String) to retrieve a for access to USB devices (as a USB host) and for controlling this device's behavior as a USB device.

static String

Use with getSystemService(java.lang.String) to retrieve a android.os.UserManager for managing users on devices that support multiple users.

static String

Use with getSystemService(java.lang.String) to retrieve a for interacting with the vibration hardware.

static String

Use with getSystemService(java.lang.String) to retrieve a com.

static String

Use with getSystemService(java.lang.String) to retrieve a android.net.wifi.aware.WifiAwareManager for handling management of Wi-Fi Aware.

static String

Use with getSystemService(java.lang.String) to retrieve a for handling management of Wi-Fi peer-to-peer connections.

static String

Use with getSystemService(java.lang.String) to retrieve a for ranging devices with wifi Note: this is a replacement for WIFI_RTT_SERVICE above.

static String

Use with getSystemService(java.lang.String) to retrieve a for handling management of Wi-Fi access.

static String

Use with getSystemService(java.lang.String) to retrieve a android.view.WindowManager for accessing the system's window manager.

Public constructors

Public methods
abstract Context!

Return the context of the single, global Application object of the current process.

abstract Unit
setWallpaper(bitmap: Bitmap!)

abstract Unit

abstract Unit

Version of removeStickyBroadcast(android.content.Intent) that allows you to specify the user the broadcast will be sent to.

abstract Int

Determine whether the calling process of an IPC or you have been granted a particular permission.

abstract ClassLoader!

Return a class loader you can use to retrieve classes in this package.

abstract Int

Determine whether the calling process of an IPC or you has been granted permission to access a specific URI.

abstract File!

Return the primary shared/external storage directory where this application's OBB files (if there are any) can be found.

abstract Int
checkUriPermission(uri: Uri!, pid: Int, uid: Int, modeFlags: Int)

Determine whether a particular process and user ID has been granted permission to access a specific URI.

abstract Int
checkUriPermission(uri: Uri?, readPermission: String?, writePermission: String?, pid: Int, uid: Int, modeFlags: Int)

Check both a Uri and normal permission.

abstract Array<File!>!

Returns absolute paths to application-specific directories on all shared/external storage devices where the application can place persistent files it owns.

abstract String!

Return the full path to this context's primary Android package.

abstract Boolean

Delete an existing shared preferences file.

abstract Int
checkPermission(permission: String, pid: Int, uid: Int)

Determine whether the given permission is allowed for a particular process and user ID running in the system.

abstract Unit
startIntentSender(intent: IntentSender!, fillInIntent: Intent?, flagsMask: Int, flagsValues: Int, extraFlags: Int)

Same as startIntentSender(android.content.IntentSender,android.content.Intent,int,int,int,android.os.Bundle) with no options specified.

abstract Unit
startIntentSender(intent: IntentSender!, fillInIntent: Intent?, flagsMask: Int, flagsValues: Int, extraFlags: Int, options: Bundle?)

Like startActivity(android.content.Intent,android.os.Bundle), but taking a IntentSender to start.

abstract SharedPreferences!

Retrieve and hold the contents of the preferences file 'name', returning a SharedPreferences through which you can retrieve and modify its values.

abstract Unit

Version of sendStickyBroadcast(android.content.Intent) that allows you to specify the user the broadcast will be sent to.

ColorStateList

Returns a color state list associated with a particular resource ID and styled for the current theme.

abstract File!

Returns the absolute path to the directory on the filesystem where all private files belonging to this app are stored.

abstract Drawable!

abstract Boolean

Indicates if the storage APIs of this Context are backed by device-protected storage.

Drawable?

Returns a drawable object associated with a particular resource ID and styled for the current theme.

abstract File?

Returns the absolute path to the directory on the primary shared/external storage device where the application can place persistent files it owns.

abstract Unit

Version of sendBroadcast(android.content.Intent) that allows you to specify the user the broadcast will be sent to.

abstract Unit
sendBroadcastAsUser(intent: Intent!, user: UserHandle!, receiverPermission: String?)

Version of sendBroadcast(android.content.Intent,java.lang.String) that allows you to specify the user the broadcast will be sent to.

open Unit
updateServiceGroup(conn: ServiceConnection, group: Int, importance: Int)

For a service previously bound with bindService or a related method, change how the system manages that service's process in relation to other processes.

abstract File?

Returns absolute path to application-specific directory on the primary shared/external storage device where the application can place cache files it owns.

abstract File!

Returns the absolute path on the filesystem where a database created with openOrCreateDatabase is stored.

abstract File!

Returns the absolute path on the filesystem where a file created with openFileOutput is stored.

abstract Boolean
stopService(service: Intent!)

Request that a given application service be stopped.

abstract Int

Determine whether you have been granted a particular permission.

abstract Intent?

Register a BroadcastReceiver to be run in the main activity thread.

abstract Intent?
registerReceiver(receiver: BroadcastReceiver?, filter: IntentFilter!, flags: Int)

Register to receive intent broadcasts, with the receiver optionally being exposed to Instant Apps.

abstract Intent?
registerReceiver(receiver: BroadcastReceiver!, filter: IntentFilter!, broadcastPermission: String?, scheduler: Handler?)

Register to receive intent broadcasts, to run in the context of scheduler.

abstract Intent?
registerReceiver(receiver: BroadcastReceiver!, filter: IntentFilter!, broadcastPermission: String?, scheduler: Handler?, flags: Int)

Register to receive intent broadcasts, to run in the context of scheduler.

abstract String?
getSystemServiceName(serviceClass: Class<*>)

Gets the name of the system-level service that is represented by the specified class.

abstract Looper!

Return the Looper for the main thread of the current process.

abstract Unit
enforceCallingOrSelfPermission(permission: String, message: String?)

If neither you nor the calling process of an IPC you are handling has been granted a particular permission, throw a SecurityException.

abstract String!

Return the full path to this context's primary Android package.

open Unit

Remove a ComponentCallbacks object that was previously registered with registerComponentCallbacks(android.content.ComponentCallbacks).

abstract Int
checkCallingUriPermission(uri: Uri!, modeFlags: Int)

Determine whether the calling process and user ID has been granted permission to access a specific URI.

abstract Int

abstract Context!

Return a new Context object for the current Context but whose storage APIs are backed by device-protected storage.

abstract FileInputStream!

Open a private file associated with this Context's application package for reading.

open Executor!

Return an Executor that will run enqueued tasks on the main thread associated with this context.

abstract File!

Returns the absolute path to the application specific cache directory on the filesystem designed for storing cached code.

abstract Boolean
bindService(service: Intent!, conn: ServiceConnection, flags: Int)

Connect to an application service, creating it if needed.

abstract Boolean

Delete an existing private SQLiteDatabase associated with this Context's application package.

abstract AssetManager!

Returns an AssetManager instance for the application's package.

abstract File!

Returns the absolute path to the directory on the filesystem similar to getFilesDir().

abstract Unit

Same as startActivities(android.content.Intent[],android.os.Bundle) with no options specified.

abstract Unit
startActivities(intents: Array<Intent!>!, options: Bundle!)

Launch multiple new activities.

abstract Resources!

Returns a Resources instance for the application's package.

String
getString(resId: Int)

Returns a localized string from the application's package's default string table.

String
getString(resId: Int, vararg formatArgs: Any!)

Returns a localized formatted string from the application's package's default string table, substituting the format arguments as defined in java.util.Formatter and java.lang.String#format.

open Unit

Add a new ComponentCallbacks to the base application of the Context, which will be called at the same times as the ComponentCallbacks methods of activities and other components are called.

abstract Array<String!>!

Returns an array of strings naming the private files associated with this Context's application package.

abstract Unit
setTheme(resid: Int)

Set the base theme for this context.

abstract Unit

Unregister a previously registered BroadcastReceiver.

abstract Unit
enforcePermission(permission: String, pid: Int, uid: Int, message: String?)

If the given permission is not allowed for a particular process and user ID running in the system, throw a SecurityException.

abstract FileOutputStream!
openFileOutput(name: String!, mode: Int)

Open a private file associated with this Context's application package for writing.

abstract Unit
sendStickyOrderedBroadcast(intent: Intent!, resultReceiver: BroadcastReceiver!, scheduler: Handler?, initialCode: Int, initialData: String?, initialExtras: Bundle?)

Version of sendStickyBroadcast that allows you to receive data back from the broadcast.

abstract Context!
createConfigurationContext(overrideConfiguration: Configuration)

Return a new Context object for the current Context but whose resources are adjusted to match the given Configuration.

abstract File!

Returns the absolute path to the directory on the filesystem where files created with openFileOutput are stored.

abstract Unit

Broadcast the given intent to all interested BroadcastReceivers.

abstract Unit
sendBroadcast(intent: Intent!, receiverPermission: String?)

Broadcast the given intent to all interested BroadcastReceivers, allowing an optional required permission to be enforced.

CharSequence
getText(resId: Int)

Return a localized, styled CharSequence from the application's package's default string table.

abstract Unit
sendOrderedBroadcastAsUser(intent: Intent!, user: UserHandle!, receiverPermission: String?, resultReceiver: BroadcastReceiver!, scheduler: Handler?, initialCode: Int, initialData: String?, initialExtras: Bundle?)

Version of sendOrderedBroadcast(android.content.Intent,java.lang.String,android.content.BroadcastReceiver,android.os.Handler,int,java.lang.String,android.os.Bundle) that allows you to specify the user the broadcast will be sent to.

abstract Unit
grantUriPermission(toPackage: String!, uri: Uri!, modeFlags: Int)

Grant permission to access a specific Uri to another package, regardless of whether that package has general permission to access the Uri's content provider.

abstract Unit
enforceCallingUriPermission(uri: Uri!, modeFlags: Int, message: String!)

If the calling process and user ID has not been granted permission to access a specific URI, throw SecurityException.

open Boolean

Indicates whether this Context is restricted.

abstract File!

Returns the absolute path to the application specific cache directory on the filesystem.

abstract Unit

abstract Unit
sendStickyOrderedBroadcastAsUser(intent: Intent!, user: UserHandle!, resultReceiver: BroadcastReceiver!, scheduler: Handler?, initialCode: Int, initialData: String?, initialExtras: Bundle?)

Version of sendStickyOrderedBroadcast(android.content.Intent,android.content.BroadcastReceiver,android.os.Handler,int,java.lang.String,android.os.Bundle) that allows you to specify the user the broadcast will be sent to.

abstract Unit

Same as startActivity(android.content.Intent,android.os.Bundle) with no options specified.

abstract Unit
startActivity(intent: Intent!, options: Bundle?)

Launch a new activity.

abstract PackageManager!

Return PackageManager instance to find global package information.

open String!

Return the package name that should be used for android.app.AppOpsManager calls from this context, so that app ops manager's uid verification will work with the name.

abstract SQLiteDatabase!

Open a new private SQLiteDatabase associated with this Context's application package.

abstract SQLiteDatabase!

Open a new private SQLiteDatabase associated with this Context's application package.

abstract Boolean

Delete the given private file associated with this Context's application package.

abstract ComponentName?
startService(service: Intent!)

Request that a given application service be started.

abstract Unit
revokeUriPermission(uri: Uri!, modeFlags: Int)

Remove all permissions to access a particular content provider Uri that were previously added with grantUriPermission or any other mechanism.

abstract Unit
revokeUriPermission(toPackage: String!, uri: Uri!, modeFlags: Int)

Remove permissions to access a particular content provider Uri that were previously added with grantUriPermission for a specific target package.

Int

Returns a color associated with a particular resource ID and styled for the current theme.

abstract Boolean
moveDatabaseFrom(sourceContext: Context!, name: String!)

Move an existing database file from the given source storage context to this context.

abstract Boolean
startInstrumentation(className: ComponentName, profileFile: String?, arguments: Bundle?)

Start executing an android.app.Instrumentation class.

abstract Unit
sendOrderedBroadcast(intent: Intent!, receiverPermission: String?)

Broadcast the given intent to all interested BroadcastReceivers, delivering them one at a time to allow more preferred receivers to consume the broadcast before it is delivered to less preferred receivers.

abstract Unit
sendOrderedBroadcast(intent: Intent, receiverPermission: String?, resultReceiver: BroadcastReceiver?, scheduler: Handler?, initialCode: Int, initialData: String?, initialExtras: Bundle?)

Version of sendBroadcast(android.content.Intent) that allows you to receive data back from the broadcast.

open Boolean
bindIsolatedService(service: Intent!, conn: ServiceConnection, flags: Int, instanceName: String)

Variation of bindService that, in the specific case of isolated services, allows the caller to generate multiple instances of a service from a single component declaration.

abstract Unit

Disconnect from an application service.

abstract ApplicationInfo!

Return the full application info for this context's package.

abstract Int

abstract Context!

Return a new Context object for the current Context but whose resources are adjusted to match the metrics of the given Display.

abstract Context!

Return a new Context object for the given split name.

abstract Resources.Theme!

Return the Theme object associated with this Context.

abstract String!

Return the name of this application's package.

abstract ContentResolver!

Return a ContentResolver instance for your application's package.

abstract Array<File!>!

Returns absolute paths to application-specific directories on all shared/external storage devices where the application's OBB files (if there are any) can be found.

TypedArray

Retrieve styled attribute information in this Context's theme.

TypedArray

Retrieve styled attribute information in this Context's theme.

TypedArray

Retrieve styled attribute information in this Context's theme.

TypedArray
obtainStyledAttributes(set: AttributeSet?, attrs: IntArray, defStyleAttr: Int, defStyleRes: Int)

Retrieve styled attribute information in this Context's theme.

abstract Unit
enforceCallingOrSelfUriPermission(uri: Uri!, modeFlags: Int, message: String!)

If the calling process of an IPC or you has not been granted permission to access a specific URI, throw SecurityException.

abstract Boolean
moveSharedPreferencesFrom(sourceContext: Context!, name: String!)

Move an existing shared preferences file from the given source storage context to this context.

abstract Array<File!>!

Returns absolute paths to application-specific directories on all shared/external storage devices where the application can place media files.

abstract Int

Determine whether the calling process of an IPC you are handling has been granted a particular permission.

abstract Array<File!>!

Returns absolute paths to application-specific directories on all shared/external storage devices where the application can place cache files it owns.

abstract Unit

Perform a sendBroadcast(android.content.Intent) that is "sticky," meaning the Intent you are sending stays around after the broadcast is complete, so that others can quickly retrieve that data through the return value of registerReceiver(android.content.BroadcastReceiver,android.content.IntentFilter).

abstract Unit
enforceCallingPermission(permission: String, message: String?)

If the calling process of an IPC you are handling has not been granted a particular permission, throw a SecurityException.

abstract Drawable!

abstract Any!

Return the handle to a system-level service by name.

T
getSystemService(serviceClass: Class<T>)

Return the handle to a system-level service by class.

abstract ComponentName?

Similar to startService(android.content.Intent), but with an implicit promise that the Service will call startForeground(int, android.app.Notification) once it begins running.

abstract File!
getDir(name: String!, mode: Int)

Retrieve, creating if needed, a new directory in which the application can place its own custom data files.

abstract Array<String!>!

Returns an array of strings naming the private databases associated with this Context's application package.

abstract Context!
createPackageContext(packageName: String!, flags: Int)

Return a new Context object for the given application name.

abstract Unit
enforceUriPermission(uri: Uri!, pid: Int, uid: Int, modeFlags: Int, message: String!)

If a particular process and user ID has not been granted permission to access a specific URI, throw SecurityException.

abstract Unit
enforceUriPermission(uri: Uri?, readPermission: String?, writePermission: String?, pid: Int, uid: Int, modeFlags: Int, message: String?)

Enforce both a Uri and normal permission.

abstract Unit

Remove the data previously sent with sendStickyBroadcast, so that it is as if the sticky broadcast had never happened.

Constants

ACCESSIBILITY_SERVICE

added in API level 4
static val ACCESSIBILITY_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.view.accessibility.AccessibilityManager for giving the user feedback for UI events through the registered event listeners.

Value: "accessibility"

ACCOUNT_SERVICE

added in API level 5
static val ACCOUNT_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.accounts.AccountManager for receiving intents at a time of your choosing.

Value: "account"

ACTIVITY_SERVICE

added in API level 1
static val ACTIVITY_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.app.ActivityManager for interacting with the global system state.

Value: "activity"

ALARM_SERVICE

added in API level 1
static val ALARM_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.app.AlarmManager for receiving intents at a time of your choosing.

Value: "alarm"

APPWIDGET_SERVICE

added in API level 21
static val APPWIDGET_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.appwidget.AppWidgetManager for accessing AppWidgets.

Value: "appwidget"

APP_OPS_SERVICE

added in API level 19
static val APP_OPS_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.app.AppOpsManager for tracking application operations on the device.

Value: "appops"

AUDIO_SERVICE

added in API level 1
static val AUDIO_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.media.AudioManager for handling management of volume, ringer modes and audio routing.

Value: "audio"

BATTERY_SERVICE

added in API level 21
static val BATTERY_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.os.BatteryManager for managing battery state.

Value: "batterymanager"

BIND_ABOVE_CLIENT

added in API level 14
static val BIND_ABOVE_CLIENT: Int

Flag for bindService: indicates that the client application binding to this service considers the service to be more important than the app itself. When set, the platform will try to have the out of memory killer kill the app before it kills the service it is bound to, though this is not guaranteed to be the case.

Value: 8

BIND_ADJUST_WITH_ACTIVITY

added in API level 14
static val BIND_ADJUST_WITH_ACTIVITY: Int

Flag for bindService: If binding from an activity, allow the target service's process importance to be raised based on whether the activity is visible to the user, regardless whether another flag is used to reduce the amount that the client process's overall importance is used to impact it.

Value: 128

BIND_ALLOW_OOM_MANAGEMENT

added in API level 14
static val BIND_ALLOW_OOM_MANAGEMENT: Int

Flag for bindService: allow the process hosting the bound service to go through its normal memory management. It will be treated more like a running service, allowing the system to (temporarily) expunge the process if low on memory or for some other whim it may have, and being more aggressive about making it a candidate to be killed (and restarted) if running for a long time.

Value: 16

BIND_AUTO_CREATE

added in API level 1
static val BIND_AUTO_CREATE: Int

Flag for bindService: automatically create the service as long as the binding exists. Note that while this will create the service, its android.app.Service#onStartCommand method will still only be called due to an explicit call to startService. Even without that, though, this still provides you with access to the service object while the service is created.

Note that prior to android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH, not supplying this flag would also impact how important the system consider's the target service's process to be. When set, the only way for it to be raised was by binding from a service in which case it will only be important when that activity is in the foreground. Now to achieve this behavior you must explicitly supply the new flag BIND_ADJUST_WITH_ACTIVITY. For compatibility, old applications that don't specify BIND_AUTO_CREATE will automatically have the flags BIND_WAIVE_PRIORITY and BIND_ADJUST_WITH_ACTIVITY set for them in order to achieve the same result.

Value: 1

BIND_DEBUG_UNBIND

added in API level 1
static val BIND_DEBUG_UNBIND: Int

Flag for bindService: include debugging help for mismatched calls to unbind. When this flag is set, the callstack of the following unbindService call is retained, to be printed if a later incorrect unbind call is made. Note that doing this requires retaining information about the binding that was made for the lifetime of the app, resulting in a leak -- this should only be used for debugging.

Value: 2

BIND_EXTERNAL_SERVICE

added in API level 24
static val BIND_EXTERNAL_SERVICE: Int

Flag for bindService: The service being bound is an isolated, external service. This binds the service into the calling application's package, rather than the package in which the service is declared.

When using this flag, the code for the service being bound will execute under the calling application's package name and user ID. Because the service must be an isolated process, it will not have direct access to the application's data, though. The purpose of this flag is to allow applications to provide services that are attributed to the app using the service, rather than the application providing the service.

Value: -2147483648

BIND_IMPORTANT

added in API level 14
static val BIND_IMPORTANT: Int

Flag for bindService: this service is very important to the client, so should be brought to the foreground process level when the client is. Normally a process can only be raised to the visibility level by a client, even if that client is in the foreground.

Value: 64

BIND_NOT_FOREGROUND

added in API level 8
static val BIND_NOT_FOREGROUND: Int

Flag for bindService: don't allow this binding to raise the target service's process to the foreground scheduling priority. It will still be raised to at least the same memory priority as the client (so that its process will not be killable in any situation where the client is not killable), but for CPU scheduling purposes it may be left in the background. This only has an impact in the situation where the binding client is a foreground process and the target service is in a background process.

Value: 4

BIND_WAIVE_PRIORITY

added in API level 14
static val BIND_WAIVE_PRIORITY: Int

Flag for bindService: don't impact the scheduling or memory management priority of the target service's hosting process. Allows the service's process to be managed on the background LRU list just like a regular application process in the background.

Value: 32

BIOMETRIC_SERVICE

added in API level Q
static val BIOMETRIC_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.hardware.biometrics.BiometricManager for handling management of face authentication.

Value: "biometric"

BLUETOOTH_SERVICE

added in API level 18
static val BLUETOOTH_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.bluetooth.BluetoothManager for using Bluetooth.

Value: "bluetooth"

CAMERA_SERVICE

added in API level 21
static val CAMERA_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.hardware.camera2.CameraManager for interacting with camera devices.

Value: "camera"

CAPTIONING_SERVICE

added in API level 19
static val CAPTIONING_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.view.accessibility.CaptioningManager for obtaining captioning properties and listening for changes in captioning preferences.

Value: "captioning"

CARRIER_CONFIG_SERVICE

added in API level 23
static val CARRIER_CONFIG_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.telephony.CarrierConfigManager for reading carrier configuration values.

Value: "carrier_config"

CLIPBOARD_SERVICE

added in API level 1
static val CLIPBOARD_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.content.ClipboardManager for accessing and modifying the contents of the global clipboard.

Value: "clipboard"

COMPANION_DEVICE_SERVICE

added in API level 26
static val COMPANION_DEVICE_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.companion.CompanionDeviceManager for managing companion devices

Value: "companiondevice"

CONNECTIVITY_SERVICE

added in API level 1
static val CONNECTIVITY_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a for handling management of network connections.

Value: "connectivity"

CONSUMER_IR_SERVICE

added in API level 19
static val CONSUMER_IR_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.hardware.ConsumerIrManager for transmitting infrared signals from the device.

Value: "consumer_ir"

CONTEXT_IGNORE_SECURITY

added in API level 1
static val CONTEXT_IGNORE_SECURITY: Int

Flag for use with createPackageContext: ignore any security restrictions on the Context being requested, allowing it to always be loaded. For use with CONTEXT_INCLUDE_CODE to allow code to be loaded into a process even when it isn't safe to do so. Use with extreme care!

Value: 2

CONTEXT_INCLUDE_CODE

added in API level 1
static val CONTEXT_INCLUDE_CODE: Int

Flag for use with createPackageContext: include the application code with the context. This means loading code into the caller's process, so that getClassLoader() can be used to instantiate the application's classes. Setting this flags imposes security restrictions on what application context you can access; if the requested application can not be safely loaded into your process, java.lang.SecurityException will be thrown. If this flag is not set, there will be no restrictions on the packages that can be loaded, but getClassLoader will always return the default system class loader.

Value: 1

CONTEXT_RESTRICTED

added in API level 4
static val CONTEXT_RESTRICTED: Int

Flag for use with createPackageContext: a restricted context may disable specific features. For instance, a View associated with a restricted context would ignore particular XML attributes.

Value: 4

CROSS_PROFILE_APPS_SERVICE

added in API level 28
static val CROSS_PROFILE_APPS_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.content.pm.CrossProfileApps for cross profile operations.

Value: "crossprofileapps"

DEVICE_POLICY_SERVICE

added in API level 8
static val DEVICE_POLICY_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.app.admin.DevicePolicyManager for working with global device policy management.

Value: "device_policy"

DISPLAY_SERVICE

added in API level 17
static val DISPLAY_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.hardware.display.DisplayManager for interacting with display devices.

Value: "display"

DOWNLOAD_SERVICE

added in API level 9
static val DOWNLOAD_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.app.DownloadManager for requesting HTTP downloads.

Value: "download"

DROPBOX_SERVICE

added in API level 8
static val DROPBOX_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.os.DropBoxManager instance for recording diagnostic logs.

Value: "dropbox"

EUICC_SERVICE

added in API level 28
static val EUICC_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.telephony.euicc.EuiccManager to manage the device eUICC (embedded SIM).

Value: "euicc"

FINGERPRINT_SERVICE

added in API level 23
static val FINGERPRINT_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.hardware.fingerprint.FingerprintManager for handling management of fingerprints.

Value: "fingerprint"

HARDWARE_PROPERTIES_SERVICE

added in API level 24
static val HARDWARE_PROPERTIES_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.os.HardwarePropertiesManager for accessing the hardware properties service.

Value: "hardware_properties"

INPUT_METHOD_SERVICE

added in API level 3
static val INPUT_METHOD_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.view.inputmethod.InputMethodManager for accessing input methods.

Value: "input_method"

INPUT_SERVICE

added in API level 16
static val INPUT_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.hardware.input.InputManager for interacting with input devices.

Value: "input"

IPSEC_SERVICE

added in API level 28
static val IPSEC_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.net.IpSecManager for encrypting Sockets or Networks with IPSec.

Value: "ipsec"

JOB_SCHEDULER_SERVICE

added in API level 21
static val JOB_SCHEDULER_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a instance for managing occasional background tasks.

Value: "jobscheduler"

KEYGUARD_SERVICE

added in API level 1
static val KEYGUARD_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.app.KeyguardManager for controlling keyguard.

Value: "keyguard"

LAUNCHER_APPS_SERVICE

added in API level 21
static val LAUNCHER_APPS_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.content.pm.LauncherApps for querying and monitoring launchable apps across profiles of a user.

Value: "launcherapps"

LAYOUT_INFLATER_SERVICE

added in API level 1
static val LAYOUT_INFLATER_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.view.LayoutInflater for inflating layout resources in this context.

Value: "layout_inflater"

LOCATION_SERVICE

added in API level 1
static val LOCATION_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a for controlling location updates.

Value: "location"

MEDIA_PROJECTION_SERVICE

added in API level 21
static val MEDIA_PROJECTION_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a instance for managing media projection sessions.

Value: "media_projection"

MEDIA_ROUTER_SERVICE

added in API level 16
static val MEDIA_ROUTER_SERVICE: String

Use with getSystemService to retrieve a android.media.MediaRouter for controlling and managing routing of media.

Value: "media_router"

MEDIA_SESSION_SERVICE

added in API level 21
static val MEDIA_SESSION_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.media.session.MediaSessionManager for managing media Sessions.

Value: "media_session"

MIDI_SERVICE

added in API level 23
static val MIDI_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.media.midi.MidiManager for accessing the MIDI service.

Value: "midi"

MODE_APPEND

added in API level 1
static val MODE_APPEND: Int

File creation mode: for use with openFileOutput, if the file already exists then write data to the end of the existing file instead of erasing it.

Value: 32768

See Also

MODE_ENABLE_WRITE_AHEAD_LOGGING

added in API level 16
static val MODE_ENABLE_WRITE_AHEAD_LOGGING: Int

Database open flag: when set, the database is opened with write-ahead logging enabled by default.

Value: 8

MODE_MULTI_PROCESS

added in API level 11
static val MODE_MULTI_PROCESS: Int

SharedPreference loading flag: when set, the file on disk will be checked for modification even if the shared preferences instance is already loaded in this process. This behavior is sometimes desired in cases where the application has multiple processes, all writing to the same SharedPreferences file. Generally there are better forms of communication between processes, though.

This was the legacy (but undocumented) behavior in and before Gingerbread (Android 2.3) and this flag is implied when targeting such releases. For applications targeting SDK versions greater than Android 2.3, this flag must be explicitly set if desired.

Value: 4

MODE_NO_LOCALIZED_COLLATORS

added in API level 24
static val MODE_NO_LOCALIZED_COLLATORS: Int

Database open flag: when set, the database is opened without support for localized collators.

Value: 16

MODE_PRIVATE

added in API level 1
static val MODE_PRIVATE: Int

File creation mode: the default mode, where the created file can only be accessed by the calling application (or all applications sharing the same user ID).

Value: 0

MODE_WORLD_READABLE

added in API level 1
static val MODE_WORLD_READABLE: Int

File creation mode: allow all other applications to have read access to the created file.

Starting from android.os.Build.VERSION_CODES#N, attempting to use this mode throws a SecurityException.

Value: 1

See Also

MODE_WORLD_WRITEABLE

added in API level 1
static val MODE_WORLD_WRITEABLE: Int

File creation mode: allow all other applications to have write access to the created file.

Starting from android.os.Build.VERSION_CODES#N, attempting to use this mode will throw a SecurityException.

Value: 2

See Also

NETWORK_STATS_SERVICE

added in API level 23
static val NETWORK_STATS_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a for querying network usage stats.

Value: "netstats"

NFC_SERVICE

added in API level 10
static val NFC_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.nfc.NfcManager for using NFC.

Value: "nfc"

NOTIFICATION_SERVICE

added in API level 1
static val NOTIFICATION_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.app.NotificationManager for informing the user of background events.

Value: "notification"

NSD_SERVICE

added in API level 16
static val NSD_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a for handling management of network service discovery

Value: "servicediscovery"

POWER_SERVICE

added in API level 1
static val POWER_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.os.PowerManager for controlling power management, including "wake locks," which let you keep the device on while you're running long tasks.

Value: "power"

PRINT_SERVICE

added in API level 19
static val PRINT_SERVICE: String

android.print.PrintManager for printing and managing printers and print tasks.

Value: "print"

RECEIVER_VISIBLE_TO_INSTANT_APPS

added in API level 26
static val RECEIVER_VISIBLE_TO_INSTANT_APPS: Int

Flag for registerReceiver: The receiver can receive broadcasts from Instant Apps.

Value: 1

RESTRICTIONS_SERVICE

added in API level 21
static val RESTRICTIONS_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.content.RestrictionsManager for retrieving application restrictions and requesting permissions for restricted operations.

Value: "restrictions"

ROLE_SERVICE

added in API level Q
static val ROLE_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.app.role.RoleManager for managing roles.

Value: "role"

SEARCH_SERVICE

added in API level 1
static val SEARCH_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a for handling searches.

Configuration#UI_MODE_TYPE_WATCH does not support android.app.SearchManager.

Value: "search"

SENSOR_SERVICE

added in API level 1
static val SENSOR_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a for accessing sensors.

Value: "sensor"

SHORTCUT_SERVICE

added in API level 25
static val SHORTCUT_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.content.pm.ShortcutManager for accessing the launcher shortcut service.

Value: "shortcut"

STORAGE_SERVICE

added in API level 9
static val STORAGE_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a for accessing system storage functions.

Value: "storage"

STORAGE_STATS_SERVICE

added in API level 26
static val STORAGE_STATS_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a for accessing system storage statistics.

Value: "storagestats"

SYSTEM_HEALTH_SERVICE

added in API level 24
static val SYSTEM_HEALTH_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.os.health.SystemHealthManager for accessing system health (battery, power, memory, etc) metrics.

Value: "systemhealth"

TELECOM_SERVICE

added in API level 21
static val TELECOM_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.telecom.TelecomManager to manage telecom-related features of the device.

Value: "telecom"

TELEPHONY_SERVICE

added in API level 1
static val TELEPHONY_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.telephony.TelephonyManager for handling management the telephony features of the device.

Value: "phone"

TELEPHONY_SUBSCRIPTION_SERVICE

added in API level 22
static val TELEPHONY_SUBSCRIPTION_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.telephony.SubscriptionManager for handling management the telephony subscriptions of the device.

Value: "telephony_subscription_service"

TEXT_CLASSIFICATION_SERVICE

added in API level 26
static val TEXT_CLASSIFICATION_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a TextClassificationManager for text classification services.

Value: "textclassification"

TEXT_SERVICES_MANAGER_SERVICE

added in API level 14
static val TEXT_SERVICES_MANAGER_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.view.textservice.TextServicesManager for accessing text services.

Value: "textservices"

TV_INPUT_SERVICE

added in API level 21
static val TV_INPUT_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.media.tv.TvInputManager for interacting with TV inputs on the device.

Value: "tv_input"

UI_MODE_SERVICE

added in API level 8
static val UI_MODE_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.app.UiModeManager for controlling UI modes.

Value: "uimode"

USAGE_STATS_SERVICE

added in API level 22
static val USAGE_STATS_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a for querying device usage stats.

Value: "usagestats"

USB_SERVICE

added in API level 12
static val USB_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a for access to USB devices (as a USB host) and for controlling this device's behavior as a USB device.

Value: "usb"

USER_SERVICE

added in API level 17
static val USER_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.os.UserManager for managing users on devices that support multiple users.

Value: "user"

VIBRATOR_SERVICE

added in API level 1
static val VIBRATOR_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a for interacting with the vibration hardware.

Value: "vibrator"

WALLPAPER_SERVICE

added in API level 1
static val WALLPAPER_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a com.android.server.WallpaperService for accessing wallpapers.

Value: "wallpaper"

WIFI_AWARE_SERVICE

added in API level 26
static val WIFI_AWARE_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.net.wifi.aware.WifiAwareManager for handling management of Wi-Fi Aware.

Value: "wifiaware"

WIFI_P2P_SERVICE

added in API level 14
static val WIFI_P2P_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a for handling management of Wi-Fi peer-to-peer connections.

Value: "wifip2p"

WIFI_RTT_RANGING_SERVICE

added in API level 28
static val WIFI_RTT_RANGING_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a for ranging devices with wifi Note: this is a replacement for WIFI_RTT_SERVICE above. It will be renamed once final implementation in place.

Value: "wifirtt"

WIFI_SERVICE

added in API level 1
static val WIFI_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a for handling management of Wi-Fi access.

Value: "wifi"

WINDOW_SERVICE

added in API level 1
static val WINDOW_SERVICE: String

Use with getSystemService(java.lang.String) to retrieve a android.view.WindowManager for accessing the system's window manager.

Value: "window"

Public constructors

<init>

Context()

Public methods

getApplicationContext

added in API level 1
abstract fun getApplicationContext(): Context!

Return the context of the single, global Application object of the current process. This generally should only be used if you need a Context whose lifecycle is separate from the current context, that is tied to the lifetime of the process rather than the current component.

Consider for example how this interacts with registerReceiver(android.content.BroadcastReceiver,android.content.IntentFilter):

  • If used from an Activity context, the receiver is being registered within that activity. This means that you are expected to unregister before the activity is done being destroyed; in fact if you do not do so, the framework will clean up your leaked registration as it removes the activity and log an error. Thus, if you use the Activity context to register a receiver that is static (global to the process, not associated with an Activity instance) then that registration will be removed on you at whatever point the activity you used is destroyed.

  • If used from the Context returned here, the receiver is being registered with the global state associated with your application. Thus it will never be unregistered for you. This is necessary if the receiver is associated with static data, not a particular component. However using the ApplicationContext elsewhere can easily lead to serious leaks if you forget to unregister, unbind, etc.

setWallpaper

added in API level 1
abstract fun setWallpaper(bitmap: Bitmap!): Unit

setWallpaper

added in API level 1
abstract fun setWallpaper(data: InputStream!): Unit

removeStickyBroadcastAsUser

added in API level 17
abstract fun removeStickyBroadcastAsUser(intent: Intent!, user: UserHandle!): Unit

Version of removeStickyBroadcast(android.content.Intent) that allows you to specify the user the broadcast will be sent to. This is not available to applications that are not pre-installed on the system image.

You must hold the android.Manifest.permission#BROADCAST_STICKY permission in order to use this API. If you do not hold that permission, SecurityException will be thrown.
Requires android.Manifest.permission.INTERACT_ACROSS_USERS and android.Manifest.permission#BROADCAST_STICKY

Parameters
intent Intent!: The Intent that was previously broadcast.
user Intent!: UserHandle to remove the sticky broadcast from.

checkCallingOrSelfPermission

added in API level 1
abstract fun checkCallingOrSelfPermission(permission: String): Int

Determine whether the calling process of an IPC or you have been granted a particular permission. This is the same as checkCallingPermission, except it grants your own permissions if you are not currently processing an IPC. Use with care!

Parameters
permission String: The name of the permission being checked. This value must never be null.
Return
Int: PackageManager#PERMISSION_GRANTED if the calling pid/uid is allowed that permission, or PackageManager#PERMISSION_DENIED if it is not. Value is android.content.pm.PackageManager#PERMISSION_GRANTED, or android.content.pm.PackageManager#PERMISSION_DENIED

getClassLoader

added in API level 1
abstract fun getClassLoader(): ClassLoader!

Return a class loader you can use to retrieve classes in this package.

checkCallingOrSelfUriPermission

added in API level 1
abstract fun checkCallingOrSelfUriPermission(uri: Uri!, modeFlags: Int): Int

Determine whether the calling process of an IPC or you has been granted permission to access a specific URI. This is the same as checkCallingUriPermission, except it grants your own permissions if you are not currently processing an IPC. Use with care!

Parameters
uri Uri!: The uri that is being checked.
modeFlags Uri!: The access modes to check. Value is either 0 or a combination of android.content.Intent#FLAG_GRANT_READ_URI_PERMISSION, and android.content.Intent#FLAG_GRANT_WRITE_URI_PERMISSION
Return
Int: PackageManager#PERMISSION_GRANTED if the caller is allowed to access that uri, or PackageManager#PERMISSION_DENIED if it is not. Value is android.content.pm.PackageManager#PERMISSION_GRANTED, or android.content.pm.PackageManager#PERMISSION_DENIED

getObbDir

added in API level 11
abstract fun getObbDir(): File!

Return the primary shared/external storage directory where this application's OBB files (if there are any) can be found. Note if the application does not have any OBB files, this directory may not exist.

This is like getFilesDir() in that these files will be deleted when the application is uninstalled, however there are some important differences:

Starting in android.os.Build.VERSION_CODES#KITKAT, no permissions are required to read or write to the path that this method returns. However, starting from android.os.Build.VERSION_CODES#M, to read the OBB expansion files, you must declare the android.Manifest.permission#READ_EXTERNAL_STORAGE permission in the app manifest and ask for permission at runtime as follows:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="23" />

Starting from android.os.Build.VERSION_CODES#N, android.Manifest.permission#READ_EXTERNAL_STORAGE permission is not required, so don’t ask for this permission at runtime. To handle both cases, your app must first try to read the OBB file, and if it fails, you must request android.Manifest.permission#READ_EXTERNAL_STORAGE permission at runtime.

The following code snippet shows how to do this:

 File obb = new File(obb_filename); boolean open_failed = false; try { BufferedReader br = new BufferedReader(new FileReader(obb)); open_failed = false; ReadObbFile(br); } catch (IOException e) { open_failed = true; } if (open_failed) { // request READ_EXTERNAL_STORAGE permission before reading OBB file ReadObbFileWithPermission(); } 
On devices with multiple users (as described by UserManager), multiple users may share the same OBB storage location. Applications should ensure that multiple instances running under different users don't interfere with each other.
Return
File!: the absolute path to application-specific directory. May return null if shared storage is not currently available.

checkUriPermission

added in API level 1
abstract fun checkUriPermission(uri: Uri!, pid: Int, uid: Int, modeFlags: Int): Int

Determine whether a particular process and user ID has been granted permission to access a specific URI. This only checks for permissions that have been explicitly granted -- if the given process/uid has more general access to the URI's content provider then this check will always fail.

Parameters
uri Uri!: The uri that is being checked.
pid Uri!: The process ID being checked against. Must be > 0.
uid Uri!: The user ID being checked against. A uid of 0 is the root user, which will pass every permission check.
modeFlags Uri!: The access modes to check. Value is either 0 or a combination of android.content.Intent#FLAG_GRANT_READ_URI_PERMISSION, and android.content.Intent#FLAG_GRANT_WRITE_URI_PERMISSION
Return
Int: PackageManager#PERMISSION_GRANTED if the given pid/uid is allowed to access that uri, or PackageManager#PERMISSION_DENIED if it is not. Value is android.content.pm.PackageManager#PERMISSION_GRANTED, or android.content.pm.PackageManager#PERMISSION_DENIED

checkUriPermission

added in API level 1
abstract fun checkUriPermission(uri: Uri?, readPermission: String?, writePermission: String?, pid: Int, uid: Int, modeFlags: Int): Int

Check both a Uri and normal permission. This allows you to perform both checkPermission and checkUriPermission in one call.

Parameters
uri Uri?: The Uri whose permission is to be checked, or null to not do this check. This value may be null.
readPermission Uri?: The permission that provides overall read access, or null to not do this check. This value may be null.
writePermission Uri?: The permission that provides overall write access, or null to not do this check. This value may be null.
pid Uri?: The process ID being checked against. Must be > 0.
uid Uri?: The user ID being checked against. A uid of 0 is the root user, which will pass every permission check.
modeFlags Uri?: The access modes to check. Value is either 0 or a combination of android.content.Intent#FLAG_GRANT_READ_URI_PERMISSION, and android.content.Intent#FLAG_GRANT_WRITE_URI_PERMISSION
Return
Int: PackageManager#PERMISSION_GRANTED if the caller is allowed to access that uri or holds one of the given permissions, or PackageManager#PERMISSION_DENIED if it is not. Value is android.content.pm.PackageManager#PERMISSION_GRANTED, or android.content.pm.PackageManager#PERMISSION_DENIED

getExternalFilesDirs

added in API level 19
abstract fun getExternalFilesDirs(type: String!): Array<File!>!

Returns absolute paths to application-specific directories on all shared/external storage devices where the application can place persistent files it owns. These files are internal to the application, and not typically visible to the user as media.

This is like getFilesDir() in that these files will be deleted when the application is uninstalled, however there are some important differences:

If a shared storage device is emulated (as determined by Environment#isExternalStorageEmulated(File)), it's contents are backed by a private user data partition, which means there is little benefit to storing data here instead of the private directories returned by getFilesDir(), etc.

Shared storage devices returned here are considered a stable part of the device, including physical media slots under a protective cover. The returned paths do not include transient devices, such as USB flash drives connected to handheld devices.

An application may store data on any or all of the returned devices. For example, an app may choose to store large files on the device with the most available space, as measured by StatFs.

No additional permissions are required for the calling app to read or write files under the returned path. Write access outside of these paths on secondary external storage devices is not available.

The returned path may change over time if different shared storage media is inserted, so only relative paths should be persisted.

Parameters
type String!: The type of files directory to return. May be null for the root of the files directory or one of the following constants for a subdirectory: android.os.Environment#DIRECTORY_MUSIC, android.os.Environment#DIRECTORY_PODCASTS, android.os.Environment#DIRECTORY_RINGTONES, android.os.Environment#DIRECTORY_ALARMS, android.os.Environment#DIRECTORY_NOTIFICATIONS, android.os.Environment#DIRECTORY_PICTURES, or android.os.Environment#DIRECTORY_MOVIES.
Return
Array<File!>!: the absolute paths to application-specific directories. Some individual paths may be null if that shared storage is not currently available. The first path returned is the same as getExternalFilesDir(java.lang.String).

getPackageResourcePath

added in API level 8
abstract fun getPackageResourcePath(): String!

Return the full path to this context's primary Android package. The Android package is a ZIP file which contains the application's primary resources.

Note: this is not generally useful for applications, since they should not be directly accessing the file system.

Return
String!: String Path to the resources.

deleteSharedPreferences

added in API level 24
abstract fun deleteSharedPreferences(name: String!): Boolean

Delete an existing shared preferences file.

Parameters
name String!: The name (unique in the application package) of the shared preferences file.
Return
Boolean: true if the shared preferences file was successfully deleted; else false.

checkPermission

added in API level 1
abstract fun checkPermission(permission: String, pid: Int, uid: Int): Int

Determine whether the given permission is allowed for a particular process and user ID running in the system.

Parameters
permission String: The name of the permission being checked. This value must never be null.
pid String: The process ID being checked against. Must be > 0.
uid String: The user ID being checked against. A uid of 0 is the root user, which will pass every permission check.
Return
Int: PackageManager#PERMISSION_GRANTED if the given pid/uid is allowed that permission, or PackageManager#PERMISSION_DENIED if it is not. Value is android.content.pm.PackageManager#PERMISSION_GRANTED, or android.content.pm.PackageManager#PERMISSION_DENIED

startIntentSender

added in API level 5
abstract fun startIntentSender(intent: IntentSender!, fillInIntent: Intent?, flagsMask: Int, flagsValues: Int, extraFlags: Int): Unit

Same as startIntentSender(android.content.IntentSender,android.content.Intent,int,int,int,android.os.Bundle) with no options specified.

Parameters
intent IntentSender!: The IntentSender to launch.
fillInIntent IntentSender!: If non-null, this will be provided as the intent parameter to IntentSender#sendIntent. This value may be null.
flagsMask IntentSender!: Intent flags in the original IntentSender that you would like to change. Value is either 0 or a combination of android.content.Intent#FLAG_FROM_BACKGROUND, android.content.Intent#FLAG_DEBUG_LOG_RESOLUTION, android.content.Intent#FLAG_EXCLUDE_STOPPED_PACKAGES, android.content.Intent#FLAG_INCLUDE_STOPPED_PACKAGES, android.content.Intent.FLAG_DEBUG_TRIAGED_MISSING, android.content.Intent.FLAG_IGNORE_EPHEMERAL, android.content.Intent#FLAG_ACTIVITY_MATCH_EXTERNAL, android.content.Intent#FLAG_ACTIVITY_NO_HISTORY, android.content.Intent#FLAG_ACTIVITY_SINGLE_TOP, android.content.Intent#FLAG_ACTIVITY_NEW_TASK, android.content.Intent#FLAG_ACTIVITY_MULTIPLE_TASK, android.content.Intent#FLAG_ACTIVITY_CLEAR_TOP, android.content.Intent#FLAG_ACTIVITY_FORWARD_RESULT, android.content.Intent#FLAG_ACTIVITY_PREVIOUS_IS_TOP, android.content.Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS, android.content.Intent#FLAG_ACTIVITY_BROUGHT_TO_FRONT, android.content.Intent#FLAG_ACTIVITY_RESET_TASK_IF_NEEDED, android.content.Intent#FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY, android.content.Intent#FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET, android.content.Intent#FLAG_ACTIVITY_NEW_DOCUMENT, android.content.Intent#FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET, android.content.Intent#FLAG_ACTIVITY_NO_USER_ACTION, android.content.Intent#FLAG_ACTIVITY_REORDER_TO_FRONT, android.content.Intent#FLAG_ACTIVITY_NO_ANIMATION, android.content.Intent#FLAG_ACTIVITY_CLEAR_TASK, android.content.Intent#FLAG_ACTIVITY_TASK_ON_HOME, android.content.Intent#FLAG_ACTIVITY_RETAIN_IN_RECENTS, android.content.Intent#FLAG_ACTIVITY_LAUNCH_ADJACENT, android.content.Intent#FLAG_RECEIVER_REGISTERED_ONLY, android.content.Intent#FLAG_RECEIVER_REPLACE_PENDING, android.content.Intent#FLAG_RECEIVER_FOREGROUND, android.content.Intent#FLAG_RECEIVER_NO_ABORT, android.content.Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT, android.content.Intent.FLAG_RECEIVER_BOOT_UPGRADE, android.content.Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND, android.content.Intent.FLAG_RECEIVER_EXCLUDE_BACKGROUND, android.content.Intent.FLAG_RECEIVER_FROM_SHELL, android.content.Intent#FLAG_RECEIVER_VISIBLE_TO_INSTANT_APPS, and android.content.Intent.FLAG_RECEIVER_OFFLOAD
flagsValues IntentSender!: Desired values for any bits set in flagsMask Value is either 0 or a combination of android.content.Intent#FLAG_FROM_BACKGROUND, android.content.Intent#FLAG_DEBUG_LOG_RESOLUTION, android.content.Intent#FLAG_EXCLUDE_STOPPED_PACKAGES, android.content.Intent#FLAG_INCLUDE_STOPPED_PACKAGES, android.content.Intent.FLAG_DEBUG_TRIAGED_MISSING, android.content.Intent.FLAG_IGNORE_EPHEMERAL, android.content.Intent#FLAG_ACTIVITY_MATCH_EXTERNAL, android.content.Intent#FLAG_ACTIVITY_NO_HISTORY, android.content.Intent#FLAG_ACTIVITY_SINGLE_TOP, android.content.Intent#FLAG_ACTIVITY_NEW_TASK, android.content.Intent#FLAG_ACTIVITY_MULTIPLE_TASK, android.content.Intent#FLAG_ACTIVITY_CLEAR_TOP, android.content.Intent#FLAG_ACTIVITY_FORWARD_RESULT, android.content.Intent#FLAG_ACTIVITY_PREVIOUS_IS_TOP, android.content.Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS, android.content.Intent#FLAG_ACTIVITY_BROUGHT_TO_FRONT, android.content.Intent#FLAG_ACTIVITY_RESET_TASK_IF_NEEDED, android.content.Intent#FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY, android.content.Intent#FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET, android.content.Intent#FLAG_ACTIVITY_NEW_DOCUMENT, android.content.Intent#FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET, android.content.Intent#FLAG_ACTIVITY_NO_USER_ACTION, android.content.Intent#FLAG_ACTIVITY_REORDER_TO_FRONT, android.content.Intent#FLAG_ACTIVITY_NO_ANIMATION, android.content.Intent#FLAG_ACTIVITY_CLEAR_TASK, android.content.Intent#FLAG_ACTIVITY_TASK_ON_HOME, android.content.Intent#FLAG_ACTIVITY_RETAIN_IN_RECENTS, android.content.Intent#FLAG_ACTIVITY_LAUNCH_ADJACENT, android.content.Intent#FLAG_RECEIVER_REGISTERED_ONLY, android.content.Intent#FLAG_RECEIVER_REPLACE_PENDING, android.content.Intent#FLAG_RECEIVER_FOREGROUND, android.content.Intent#FLAG_RECEIVER_NO_ABORT, android.content.Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT, android.content.Intent.FLAG_RECEIVER_BOOT_UPGRADE, android.content.Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND, android.content.Intent.FLAG_RECEIVER_EXCLUDE_BACKGROUND, android.content.Intent.FLAG_RECEIVER_FROM_SHELL, android.content.Intent#FLAG_RECEIVER_VISIBLE_TO_INSTANT_APPS, and android.content.Intent.FLAG_RECEIVER_OFFLOAD
extraFlags IntentSender!: Always set to 0.

startIntentSender

added in API level 16
abstract fun startIntentSender(intent: IntentSender!, fillInIntent: Intent?, flagsMask: Int, flagsValues: Int, extraFlags: Int, options: Bundle?): Unit

Like startActivity(android.content.Intent,android.os.Bundle), but taking a IntentSender to start. If the IntentSender is for an activity, that activity will be started as if you had called the regular startActivity(android.content.Intent) here; otherwise, its associated action will be executed (such as sending a broadcast) as if you had called IntentSender#sendIntent on it.

Parameters
intent IntentSender!: The IntentSender to launch.
fillInIntent IntentSender!: If non-null, this will be provided as the intent parameter to IntentSender#sendIntent. This value may be null.
flagsMask IntentSender!: Intent flags in the original IntentSender that you would like to change. Value is either 0 or a combination of android.content.Intent#FLAG_FROM_BACKGROUND, android.content.Intent#FLAG_DEBUG_LOG_RESOLUTION, android.content.Intent#FLAG_EXCLUDE_STOPPED_PACKAGES, android.content.Intent#FLAG_INCLUDE_STOPPED_PACKAGES, android.content.Intent.FLAG_DEBUG_TRIAGED_MISSING, android.content.Intent.FLAG_IGNORE_EPHEMERAL, android.content.Intent#FLAG_ACTIVITY_MATCH_EXTERNAL, android.content.Intent#FLAG_ACTIVITY_NO_HISTORY, android.content.Intent#FLAG_ACTIVITY_SINGLE_TOP, android.content.Intent#FLAG_ACTIVITY_NEW_TASK, android.content.Intent#FLAG_ACTIVITY_MULTIPLE_TASK, android.content.Intent#FLAG_ACTIVITY_CLEAR_TOP, android.content.Intent#FLAG_ACTIVITY_FORWARD_RESULT, android.content.Intent#FLAG_ACTIVITY_PREVIOUS_IS_TOP, android.content.Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS, android.content.Intent#FLAG_ACTIVITY_BROUGHT_TO_FRONT, android.content.Intent#FLAG_ACTIVITY_RESET_TASK_IF_NEEDED, android.content.Intent#FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY, android.content.Intent#FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET, android.content.Intent#FLAG_ACTIVITY_NEW_DOCUMENT, android.content.Intent#FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET, android.content.Intent#FLAG_ACTIVITY_NO_USER_ACTION, android.content.Intent#FLAG_ACTIVITY_REORDER_TO_FRONT, android.content.Intent#FLAG_ACTIVITY_NO_ANIMATION, android.content.Intent#FLAG_ACTIVITY_CLEAR_TASK, android.content.Intent#FLAG_ACTIVITY_TASK_ON_HOME, android.content.Intent#FLAG_ACTIVITY_RETAIN_IN_RECENTS, android.content.Intent#FLAG_ACTIVITY_LAUNCH_ADJACENT, android.content.Intent#FLAG_RECEIVER_REGISTERED_ONLY, android.content.Intent#FLAG_RECEIVER_REPLACE_PENDING, android.content.Intent#FLAG_RECEIVER_FOREGROUND, android.content.Intent#FLAG_RECEIVER_NO_ABORT, android.content.Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT, android.content.Intent.FLAG_RECEIVER_BOOT_UPGRADE, android.content.Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND, android.content.Intent.FLAG_RECEIVER_EXCLUDE_BACKGROUND, android.content.Intent.FLAG_RECEIVER_FROM_SHELL, android.content.Intent#FLAG_RECEIVER_VISIBLE_TO_INSTANT_APPS, and android.content.Intent.FLAG_RECEIVER_OFFLOAD
flagsValues IntentSender!: Desired values for any bits set in flagsMask Value is either 0 or a combination of android.content.Intent#FLAG_FROM_BACKGROUND, android.content.Intent#FLAG_DEBUG_LOG_RESOLUTION, android.content.Intent#FLAG_EXCLUDE_STOPPED_PACKAGES, android.content.Intent#FLAG_INCLUDE_STOPPED_PACKAGES, android.content.Intent.FLAG_DEBUG_TRIAGED_MISSING, android.content.Intent.FLAG_IGNORE_EPHEMERAL, android.content.Intent#FLAG_ACTIVITY_MATCH_EXTERNAL, android.content.Intent#FLAG_ACTIVITY_NO_HISTORY, android.content.Intent#FLAG_ACTIVITY_SINGLE_TOP, android.content.Intent#FLAG_ACTIVITY_NEW_TASK, android.content.Intent#FLAG_ACTIVITY_MULTIPLE_TASK, android.content.Intent#FLAG_ACTIVITY_CLEAR_TOP, android.content.Intent#FLAG_ACTIVITY_FORWARD_RESULT, android.content.Intent#FLAG_ACTIVITY_PREVIOUS_IS_TOP, android.content.Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS, android.content.Intent#FLAG_ACTIVITY_BROUGHT_TO_FRONT, android.content.Intent#FLAG_ACTIVITY_RESET_TASK_IF_NEEDED, android.content.Intent#FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY, android.content.Intent#FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET, android.content.Intent#FLAG_ACTIVITY_NEW_DOCUMENT, android.content.Intent#FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET, android.content.Intent#FLAG_ACTIVITY_NO_USER_ACTION, android.content.Intent#FLAG_ACTIVITY_REORDER_TO_FRONT, android.content.Intent#FLAG_ACTIVITY_NO_ANIMATION, android.content.Intent#FLAG_ACTIVITY_CLEAR_TASK, android.content.Intent#FLAG_ACTIVITY_TASK_ON_HOME, android.content.Intent#FLAG_ACTIVITY_RETAIN_IN_RECENTS, android.content.Intent#FLAG_ACTIVITY_LAUNCH_ADJACENT, android.content.Intent#FLAG_RECEIVER_REGISTERED_ONLY, android.content.Intent#FLAG_RECEIVER_REPLACE_PENDING, android.content.Intent#FLAG_RECEIVER_FOREGROUND, android.content.Intent#FLAG_RECEIVER_NO_ABORT, android.content.Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT, android.content.Intent.FLAG_RECEIVER_BOOT_UPGRADE, android.content.Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND, android.content.Intent.FLAG_RECEIVER_EXCLUDE_BACKGROUND, android.content.Intent.FLAG_RECEIVER_FROM_SHELL, android.content.Intent#FLAG_RECEIVER_VISIBLE_TO_INSTANT_APPS, and android.content.Intent.FLAG_RECEIVER_OFFLOAD
extraFlags IntentSender!: Always set to 0.
options IntentSender!: Additional options for how the Activity should be started. See android.content.Context#startActivity(Intent, Bundle) Context.startActivity(Intent, Bundle)} for more details. If options have also been supplied by the IntentSender, options given here will override any that conflict with those given by the IntentSender. This value may be null.

getSharedPreferences

added in API level 1
abstract fun getSharedPreferences(name: String!, mode: Int): SharedPreferences!

Retrieve and hold the contents of the preferences file 'name', returning a SharedPreferences through which you can retrieve and modify its values. Only one instance of the SharedPreferences object is returned to any callers for the same name, meaning they will see each other's edits as soon as they are made. This method is thead-safe.

Parameters
name String!: Desired preferences file. If a preferences file by this name does not exist, it will be created when you retrieve an editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
mode String!: Operating mode. Value is either 0 or a combination of android.content.Context#MODE_PRIVATE, android.content.Context#MODE_WORLD_READABLE, android.content.Context#MODE_WORLD_WRITEABLE, and android.content.Context#MODE_MULTI_PROCESS
Return
SharedPreferences!: The single SharedPreferences instance that can be used to retrieve and modify the preference values.

See Also

sendStickyBroadcastAsUser

added in API level 17
abstract fun sendStickyBroadcastAsUser(intent: Intent!, user: UserHandle!): Unit

Version of sendStickyBroadcast(android.content.Intent) that allows you to specify the user the broadcast will be sent to. This is not available to applications that are not pre-installed on the system image.
Requires android.Manifest.permission.INTERACT_ACROSS_USERS and android.Manifest.permission#BROADCAST_STICKY

Parameters
intent Intent!: The Intent to broadcast; all receivers matching this Intent will receive the broadcast, and the Intent will be held to be re-broadcast to future receivers.
user Intent!: UserHandle to send the intent to.

getColorStateList

added in API level 23
fun getColorStateList(id: Int): ColorStateList

Returns a color state list associated with a particular resource ID and styled for the current theme.

Parameters
id Int: The desired resource identifier, as generated by the aapt tool. This integer encodes the package, type, and resource entry. The value 0 is an invalid identifier.
Return
ColorStateList: A color state list. This value will never be null.
Exceptions
android.content.res.Resources.NotFoundException if the given ID does not exist.

getDataDir

added in API level 24
abstract fun getDataDir(): File!

Returns the absolute path to the directory on the filesystem where all private files belonging to this app are stored. Apps should not use this path directly; they should instead use getFilesDir(), getCacheDir(), getDir(java.lang.String,int), or other storage APIs on this class.

The returned path may change over time if the calling app is moved to an adopted storage device, so only relative paths should be persisted.

No additional permissions are required for the calling app to read or write files under the returned path.

getWallpaper

added in API level 1
abstract fun getWallpaper(): Drawable!

isDeviceProtectedStorage

added in API level 24
abstract fun isDeviceProtectedStorage(): Boolean

Indicates if the storage APIs of this Context are backed by device-protected storage.

getDrawable

added in API level 21
fun getDrawable(id: Int): Drawable?

Returns a drawable object associated with a particular resource ID and styled for the current theme.

Parameters
id Int: The desired resource identifier, as generated by the aapt tool. This integer encodes the package, type, and resource entry. The value 0 is an invalid identifier.
Return
Drawable?: An object that can be used to draw this resource. This value may be null.
Exceptions
android.content.res.Resources.NotFoundException if the given ID does not exist.

getExternalFilesDir

added in API level 8
abstract fun getExternalFilesDir(type: String?): File?

Returns the absolute path to the directory on the primary shared/external storage device where the application can place persistent files it owns. These files are internal to the applications, and not typically visible to the user as media.

This is like getFilesDir() in that these files will be deleted when the application is uninstalled, however there are some important differences:

If a shared storage device is emulated (as determined by Environment#isExternalStorageEmulated(File)), it's contents are backed by a private user data partition, which means there is little benefit to storing data here instead of the private directories returned by getFilesDir(), etc.

Starting in android.os.Build.VERSION_CODES#KITKAT, no permissions are required to read or write to the returned path; it's always accessible to the calling app. This only applies to paths generated for package name of the calling application. To access paths belonging to other packages, android.Manifest.permission#WRITE_EXTERNAL_STORAGE and/or android.Manifest.permission#READ_EXTERNAL_STORAGE are required.

On devices with multiple users (as described by UserManager), each user has their own isolated shared storage. Applications only have access to the shared storage for the user they're running as.

The returned path may change over time if different shared storage media is inserted, so only relative paths should be persisted.

Here is an example of typical code to manipulate a file in an application's shared storage:

{@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java * private_file}

If you supply a non-null type to this function, the returned file will be a path to a sub-directory of the given type. Though these files are not automatically scanned by the media scanner, you can explicitly add them to the media database with MediaScannerConnection.scanFile. Note that this is not the same as Environment.getExternalStoragePublicDirectory(), which provides directories of media shared by all applications. The directories returned here are owned by the application, and their contents will be removed when the application is uninstalled. Unlike Environment.getExternalStoragePublicDirectory(), the directory returned here will be automatically created for you.

Here is an example of typical code to manipulate a picture in an application's shared storage and add it to the media database:

{@sample development/samples/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java * private_picture}
Parameters
type String?: The type of files directory to return. May be null for the root of the files directory or one of the following constants for a subdirectory: android.os.Environment#DIRECTORY_MUSIC, android.os.Environment#DIRECTORY_PODCASTS, android.os.Environment#DIRECTORY_RINGTONES, android.os.Environment#DIRECTORY_ALARMS, android.os.Environment#DIRECTORY_NOTIFICATIONS, android.os.Environment#DIRECTORY_PICTURES, or android.os.Environment#DIRECTORY_MOVIES. This value may be null.
Return
File?: the absolute path to application-specific directory. May return null if shared storage is not currently available.

sendBroadcastAsUser

added in API level 17
abstract fun sendBroadcastAsUser(intent: Intent!, user: UserHandle!): Unit

Version of sendBroadcast(android.content.Intent) that allows you to specify the user the broadcast will be sent to. This is not available to applications that are not pre-installed on the system image.
Requires android.Manifest.permission.INTERACT_ACROSS_USERS

Parameters
intent Intent!: The intent to broadcast
user Intent!: UserHandle to send the intent to.

sendBroadcastAsUser

added in API level 17
abstract fun sendBroadcastAsUser(intent: Intent!, user: UserHandle!, receiverPermission: String?): Unit

Version of sendBroadcast(android.content.Intent,java.lang.String) that allows you to specify the user the broadcast will be sent to. This is not available to applications that are not pre-installed on the system image.
Requires android.Manifest.permission.INTERACT_ACROSS_USERS

Parameters
intent Intent!: The Intent to broadcast; all receivers matching this Intent will receive the broadcast.
user Intent!: UserHandle to send the intent to.
receiverPermission Intent!: (optional) String naming a permission that a receiver must hold in order to receive your broadcast. If null, no permission is required. This value may be null.

updateServiceGroup

added in API level Q
open fun updateServiceGroup(conn: ServiceConnection, group: Int, importance: Int): Unit

For a service previously bound with bindService or a related method, change how the system manages that service's process in relation to other processes. This doesn't modify the original bind flags that were passed in when binding, but adjusts how the process will be managed in some cases based on those flags. Currently only works on isolated processes (will be ignored for non-isolated processes).

Note that this call does not take immediate effect, but will be applied the next time the impacted process is adjusted for some other reason. Typically you would call this before then calling a new bindIsolatedService on the service of interest, with that binding causing the process to be shuffled accordingly.

Parameters
conn ServiceConnection: The connection interface previously supplied to bindService(). This parameter must not be null. This value must never be null.
group ServiceConnection: A group to put this connection's process in. Upon calling here, this will override any previous group that was set for that process. The group tells the system about processes that are logically grouped together, so should be managed as one unit of importance (such as when being considered a recently used app). All processes in the same app with the same group are considered to be related. Supplying 0 reverts to the default behavior of not grouping.
importance ServiceConnection: Additional importance of the processes within a group. Upon calling here, this will override any previous group that was set for that process. This fine-tunes process killing of all processes within a related groups -- higher importance values will be killed before lower ones.

getExternalCacheDir

added in API level 8
abstract fun getExternalCacheDir(): File?

Returns absolute path to application-specific directory on the primary shared/external storage device where the application can place cache files it owns. These files are internal to the application, and not typically visible to the user as media.

This is like getCacheDir() in that these files will be deleted when the application is uninstalled, however there are some important differences:

If a shared storage device is emulated (as determined by Environment#isExternalStorageEmulated(File)), its contents are backed by a private user data partition, which means there is little benefit to storing data here instead of the private directory returned by getCacheDir().

Starting in android.os.Build.VERSION_CODES#KITKAT, no permissions are required to read or write to the returned path; it's always accessible to the calling app. This only applies to paths generated for package name of the calling application. To access paths belonging to other packages, android.Manifest.permission#WRITE_EXTERNAL_STORAGE and/or android.Manifest.permission#READ_EXTERNAL_STORAGE are required.

On devices with multiple users (as described by UserManager), each user has their own isolated shared storage. Applications only have access to the shared storage for the user they're running as.

The returned path may change over time if different shared storage media is inserted, so only relative paths should be persisted.

Return
File?: the absolute path to application-specific directory. May return null if shared storage is not currently available.

getDatabasePath

added in API level 1
abstract fun getDatabasePath(name: String!): File!

Returns the absolute path on the filesystem where a database created with openOrCreateDatabase is stored.

The returned path may change over time if the calling app is moved to an adopted storage device, so only relative paths should be persisted.

Parameters
name String!: The name of the database for which you would like to get its path.
Return
File!: An absolute path to the given database.

getFileStreamPath

added in API level 1
abstract fun getFileStreamPath(name: String!): File!

Returns the absolute path on the filesystem where a file created with openFileOutput is stored.

The returned path may change over time if the calling app is moved to an adopted storage device, so only relative paths should be persisted.

Parameters
name String!: The name of the file for which you would like to get its path.
Return
File!: An absolute path to the given file.

stopService

added in API level 1
abstract fun stopService(service: Intent!): Boolean

Request that a given application service be stopped. If the service is not running, nothing happens. Otherwise it is stopped. Note that calls to startService() are not counted -- this stops the service no matter how many times it was started.

Note that if a stopped service still has ServiceConnection objects bound to it with the BIND_AUTO_CREATE set, it will not be destroyed until all of these bindings are removed. See the android.app.Service documentation for more details on a service's lifecycle.

This function will throw SecurityException if you do not have permission to stop the given service.

Parameters
service Intent!: Description of the service to be stopped. The Intent must be either fully explicit (supplying a component name) or specify a specific package name it is targeted to.
Return
Boolean: If there is a service matching the given Intent that is already running, then it is stopped and true is returned; else false is returned.
Exceptions
java.lang.SecurityException If the caller does not have permission to access the service or the service can not be found.
java.lang.IllegalStateException If the application is in a state where the service can not be started (such as not in the foreground in a state when services are allowed).

See Also

checkSelfPermission

added in API level 23
abstract fun checkSelfPermission(permission: String): Int

Determine whether you have been granted a particular permission.

Parameters
permission String: The name of the permission being checked. This value must never be null.
Return
Int: PackageManager#PERMISSION_GRANTED if you have the permission, or PackageManager#PERMISSION_DENIED if not. Value is android.content.pm.PackageManager#PERMISSION_GRANTED, or android.content.pm.PackageManager#PERMISSION_DENIED

registerReceiver

added in API level 1
abstract fun registerReceiver(receiver: BroadcastReceiver?, filter: IntentFilter!): Intent?

Register a BroadcastReceiver to be run in the main activity thread. The receiver will be called with any broadcast Intent that matches filter, in the main application thread.

The system may broadcast Intents that are "sticky" -- these stay around after the broadcast has finished, to be sent to any later registrations. If your IntentFilter matches one of these sticky Intents, that Intent will be returned by this function and sent to your receiver as if it had just been broadcast.

There may be multiple sticky Intents that match filter, in which case each of these will be sent to receiver. In this case, only one of these can be returned directly by the function; which of these that is returned is arbitrarily decided by the system.

If you know the Intent your are registering for is sticky, you can supply null for your receiver. In this case, no receiver is registered -- the function simply returns the sticky Intent that matches filter. In the case of multiple matches, the same rules as described above apply.

See BroadcastReceiver for more information on Intent broadcasts.

As of android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH, receivers registered with this method will correctly respect the Intent#setPackage(String) specified for an Intent being broadcast. Prior to that, it would be ignored and delivered to all matching registered receivers. Be careful if using this for security.

Note: this method cannot be called from a BroadcastReceiver component; that is, from a BroadcastReceiver that is declared in an application's manifest. It is okay, however, to call this method from another BroadcastReceiver that has itself been registered at run time with registerReceiver, since the lifetime of such a registered BroadcastReceiver is tied to the object that registered it.

Parameters
receiver BroadcastReceiver?: The BroadcastReceiver to handle the broadcast. This value may be null.
filter BroadcastReceiver?: Selects the Intent broadcasts to be received.
Return
Intent?: The first sticky intent found that matches filter, or null if there are none.

registerReceiver

added in API level 26
abstract fun registerReceiver(receiver: BroadcastReceiver?, filter: IntentFilter!, flags: Int): Intent?

Register to receive intent broadcasts, with the receiver optionally being exposed to Instant Apps. See registerReceiver(android.content.BroadcastReceiver,android.content.IntentFilter) for more information. By default Instant Apps cannot interact with receivers in other applications, this allows you to expose a receiver that Instant Apps can interact with.

See BroadcastReceiver for more information on Intent broadcasts.

As of android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH, receivers registered with this method will correctly respect the Intent#setPackage(String) specified for an Intent being broadcast. Prior to that, it would be ignored and delivered to all matching registered receivers. Be careful if using this for security.

Parameters
receiver BroadcastReceiver?: The BroadcastReceiver to handle the broadcast. This value may be null.
filter BroadcastReceiver?: Selects the Intent broadcasts to be received.
flags BroadcastReceiver?: Additional options for the receiver. May be 0 or RECEIVER_VISIBLE_TO_INSTANT_APPS. Value is either 0 or android.content.Context#RECEIVER_VISIBLE_TO_INSTANT_APPS
Return
Intent?: The first sticky intent found that matches filter, or null if there are none.

registerReceiver

added in API level 1
abstract fun registerReceiver(receiver: BroadcastReceiver!, filter: IntentFilter!, broadcastPermission: String?, scheduler: Handler?): Intent?

Register to receive intent broadcasts, to run in the context of scheduler. See registerReceiver(android.content.BroadcastReceiver,android.content.IntentFilter) for more information. This allows you to enforce permissions on who can broadcast intents to your receiver, or have the receiver run in a different thread than the main application thread.

See BroadcastReceiver for more information on Intent broadcasts.

As of android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH, receivers registered with this method will correctly respect the Intent#setPackage(String) specified for an Intent being broadcast. Prior to that, it would be ignored and delivered to all matching registered receivers. Be careful if using this for security.

Parameters
receiver BroadcastReceiver!: The BroadcastReceiver to handle the broadcast.
filter BroadcastReceiver!: Selects the Intent broadcasts to be received.
broadcastPermission BroadcastReceiver!: String naming a permissions that a broadcaster must hold in order to send an Intent to you. If null, no permission is required. This value may be null.
scheduler BroadcastReceiver!: Handler identifying the thread that will receive the Intent. If null, the main thread of the process will be used. This value may be null.
Return
Intent?: The first sticky intent found that matches filter, or null if there are none.

registerReceiver

added in API level 26
abstract fun registerReceiver(receiver: BroadcastReceiver!, filter: IntentFilter!, broadcastPermission: String?, scheduler: Handler?, flags: Int): Intent?

Register to receive intent broadcasts, to run in the context of scheduler. See registerReceiver(android.content.BroadcastReceiver,android.content.IntentFilter,int) and registerReceiver(android.content.BroadcastReceiver,android.content.IntentFilter,java.lang.String,android.os.Handler) for more information.

See BroadcastReceiver for more information on Intent broadcasts.

As of android.os.Build.VERSION_CODES#ICE_CREAM_SANDWICH, receivers registered with this method will correctly respect the Intent#setPackage(String) specified for an Intent being broadcast. Prior to that, it would be ignored and delivered to all matching registered receivers. Be careful if using this for security.

Parameters
receiver BroadcastReceiver!: The BroadcastReceiver to handle the broadcast.
filter BroadcastReceiver!: Selects the Intent broadcasts to be received.
broadcastPermission BroadcastReceiver!: String naming a permissions that a broadcaster must hold in order to send an Intent to you. If null, no permission is required. This value may be null.
scheduler BroadcastReceiver!: Handler identifying the thread that will receive the Intent. If null, the main thread of the process will be used. This value may be null.
flags BroadcastReceiver!: Additional options for the receiver. May be 0 or RECEIVER_VISIBLE_TO_INSTANT_APPS. Value is either 0 or android.content.Context#RECEIVER_VISIBLE_TO_INSTANT_APPS
Return
Intent?: The first sticky intent found that matches filter, or null if there are none.

getSystemServiceName

added in API level 23
abstract fun getSystemServiceName(serviceClass: Class<*>): String?

Gets the name of the system-level service that is represented by the specified class.

Parameters
serviceClass Class<*>: The class of the desired service. This value must never be null.
Return
String?: The service name or null if the class is not a supported system service.

getMainLooper

added in API level 1
abstract fun getMainLooper(): Looper!

Return the Looper for the main thread of the current process. This is the thread used to dispatch calls to application components (activities, services, etc).

By definition, this method returns the same result as would be obtained by calling Looper#getMainLooper().

Return
Looper!: The main looper.

enforceCallingOrSelfPermission

added in API level 1
abstract fun enforceCallingOrSelfPermission(permission: String, message: String?): Unit

If neither you nor the calling process of an IPC you are handling has been granted a particular permission, throw a SecurityException. This is the same as , except it grants your own permissions if you are not currently processing an IPC. Use with care!

Parameters
permission String: The name of the permission being checked. This value must never be null.
message String: A message to include in the exception if it is thrown. This value may be null.

getPackageCodePath

added in API level 8
abstract fun getPackageCodePath(): String!

Return the full path to this context's primary Android package. The Android package is a ZIP file which contains application's primary code and assets.

Note: this is not generally useful for applications, since they should not be directly accessing the file system.

Return
String!: String Path to the code and assets.

unregisterComponentCallbacks

added in API level 14
open fun unregisterComponentCallbacks(callback: ComponentCallbacks!): Unit

Remove a ComponentCallbacks object that was previously registered with registerComponentCallbacks(android.content.ComponentCallbacks).

checkCallingUriPermission

added in API level 1
abstract fun checkCallingUriPermission(uri: Uri!, modeFlags: Int): Int

Determine whether the calling process and user ID has been granted permission to access a specific URI. This is basically the same as calling checkUriPermission(android.net.Uri,int,int,int) with the pid and uid returned by and . One important difference is that if you are not currently processing an IPC, this function will always fail.

Parameters
uri Uri!: The uri that is being checked.
modeFlags Uri!: The access modes to check. Value is either 0 or a combination of android.content.Intent#FLAG_GRANT_READ_URI_PERMISSION, and android.content.Intent#FLAG_GRANT_WRITE_URI_PERMISSION
Return
Int: PackageManager#PERMISSION_GRANTED if the caller is allowed to access that uri, or PackageManager#PERMISSION_DENIED if it is not. Value is android.content.pm.PackageManager#PERMISSION_GRANTED, or android.content.pm.PackageManager#PERMISSION_DENIED

getWallpaperDesiredMinimumWidth

added in API level 1
abstract fun getWallpaperDesiredMinimumWidth(): Int

createDeviceProtectedStorageContext

added in API level 24
abstract fun createDeviceProtectedStorageContext(): Context!

Return a new Context object for the current Context but whose storage APIs are backed by device-protected storage.

On devices with direct boot, data stored in this location is encrypted with a key tied to the physical device, and it can be accessed immediately after the device has booted successfully, both before and after the user has authenticated with their credentials (such as a lock pattern or PIN).

Because device-protected data is available without user authentication, you should carefully limit the data you store using this Context. For example, storing sensitive authentication tokens or passwords in the device-protected area is strongly discouraged.

If the underlying device does not have the ability to store device-protected and credential-protected data using different keys, then both storage areas will become available at the same time. They remain as two distinct storage locations on disk, and only the window of availability changes.

Each call to this method returns a new instance of a Context object; Context objects are not shared, however common state (ClassLoader, other Resources for the same configuration) may be so the Context itself can be fairly lightweight.

openFileInput

added in API level 1
abstract fun openFileInput(name: String!): FileInputStream!

Open a private file associated with this Context's application package for reading.

Parameters
name String!: The name of the file to open; can not contain path separators.
Return
FileInputStream!: The resulting FileInputStream.

getMainExecutor

added in API level 28
open fun getMainExecutor(): Executor!

Return an Executor that will run enqueued tasks on the main thread associated with this context. This is the thread used to dispatch calls to application components (activities, services, etc).

getCodeCacheDir

added in API level 21
abstract fun getCodeCacheDir(): File!

Returns the absolute path to the application specific cache directory on the filesystem designed for storing cached code.

The system will delete any files stored in this location both when your specific application is upgraded, and when the entire platform is upgraded.

This location is optimal for storing compiled or optimized code generated by your application at runtime.

The returned path may change over time if the calling app is moved to an adopted storage device, so only relative paths should be persisted.

Apps require no extra permissions to read or write to the returned path, since this path lives in their private storage.

Return
File!: The path of the directory holding application code cache files.

bindService

added in API level 1
abstract fun bindService(service: Intent!, conn: ServiceConnection, flags: Int): Boolean

Connect to an application service, creating it if needed. This defines a dependency between your application and the service. The given conn will receive the service object when it is created and be told if it dies and restarts. The service will be considered required by the system only for as long as the calling context exists. For example, if this Context is an Activity that is stopped, the service will not be required to continue running until the Activity is resumed.

If the service does not support binding, it may return null from its onBind() method. If it does, then the ServiceConnection's ServiceConnection#onNullBinding(ComponentName) method will be invoked instead of ServiceConnection#onServiceConnected(ComponentName, IBinder).

This method will throw SecurityException if the calling app does not have permission to bind to the given service.

Note: this method cannot be called from a BroadcastReceiver component. A pattern you can use to communicate from a BroadcastReceiver to a Service is to call startService with the arguments containing the command to be sent, with the service calling its android.app.Service#stopSelf(int) method when done executing that command. See the API demo App/Service/Service Start Arguments Controller for an illustration of this. It is okay, however, to use this method from a BroadcastReceiver that has been registered with registerReceiver, since the lifetime of this BroadcastReceiver is tied to another object (the one that registered it).

Parameters
service Intent!: Identifies the service to connect to. The Intent must specify an explicit component name.
conn Intent!: Receives information as the service is started and stopped. This must be a valid ServiceConnection object; it must not be null. This value must never be null.
flags Intent!: Operation options for the binding. May be 0, BIND_AUTO_CREATE, BIND_DEBUG_UNBIND, BIND_NOT_FOREGROUND, BIND_ABOVE_CLIENT, BIND_ALLOW_OOM_MANAGEMENT, BIND_WAIVE_PRIORITY. BIND_IMPORTANT, or BIND_ADJUST_WITH_ACTIVITY. Value is either 0 or a combination of android.content.Context#BIND_AUTO_CREATE, android.content.Context#BIND_DEBUG_UNBIND, android.content.Context#BIND_NOT_FOREGROUND, android.content.Context#BIND_ABOVE_CLIENT, android.content.Context#BIND_ALLOW_OOM_MANAGEMENT, android.content.Context#BIND_WAIVE_PRIORITY, android.content.Context#BIND_IMPORTANT, and android.content.Context#BIND_ADJUST_WITH_ACTIVITY
Return
Boolean: true if the system is in the process of bringing up a service that your client has permission to bind to; false if the system couldn't find the service or if your client doesn't have permission to bind to it. If this value is true, you should later call unbindService to release the connection.
Exceptions
java.lang.SecurityException If the caller does not have permission to access the service or the service can not be found.

deleteDatabase

added in API level 1
abstract fun deleteDatabase(name: String!): Boolean

Delete an existing private SQLiteDatabase associated with this Context's application package.

Parameters
name String!: The name (unique in the application package) of the database.
Return
Boolean: true if the database was successfully deleted; else false.

getAssets

added in API level 1
abstract fun getAssets(): AssetManager!

Returns an AssetManager instance for the application's package.

Note: Implementations of this method should return an AssetManager instance that is consistent with the Resources instance returned by getResources(). For example, they should share the same Configuration object.

Return
AssetManager!: an AssetManager instance for the application's package

See Also

getNoBackupFilesDir

added in API level 21
abstract fun getNoBackupFilesDir(): File!

Returns the absolute path to the directory on the filesystem similar to getFilesDir(). The difference is that files placed under this directory will be excluded from automatic backup to remote storage. See BackupAgent for a full discussion of the automatic backup mechanism in Android.

The returned path may change over time if the calling app is moved to an adopted storage device, so only relative paths should be persisted.

No additional permissions are required for the calling app to read or write files under the returned path.

Return
File!: The path of the directory holding application files that will not be automatically backed up to remote storage.

startActivities

added in API level 11
abstract fun startActivities(intents: Array<Intent!>!): Unit

Same as startActivities(android.content.Intent[],android.os.Bundle) with no options specified.

Parameters
intents Array<Intent!>!: An array of Intents to be started.
Exceptions
android.content.ActivityNotFoundException  

startActivities

added in API level 16
abstract fun startActivities(intents: Array<Intent!>!, options: Bundle!): Unit

Launch multiple new activities. This is generally the same as calling startActivity(android.content.Intent) for the first Intent in the array, that activity during its creation calling startActivity(android.content.Intent) for the second entry, etc. Note that unlike that approach, generally none of the activities except the last in the array will be created at this point, but rather will be created when the user first visits them (due to pressing back from the activity on top).

This method throws ActivityNotFoundException if there was no Activity found for any given Intent. In this case the state of the activity stack is undefined (some Intents in the list may be on it, some not), so you probably want to avoid such situations.

Parameters
intents Array<Intent!>!: An array of Intents to be started.
options Array<Intent!>!: Additional options for how the Activity should be started. See android.content.Context#startActivity(Intent, Bundle) Context.startActivity(Intent, Bundle)} for more details.
Exceptions
android.content.ActivityNotFoundException  

getResources

added in API level 1
abstract fun getResources(): Resources!

Returns a Resources instance for the application's package.

Note: Implementations of this method should return a Resources instance that is consistent with the AssetManager instance returned by getAssets(). For example, they should share the same Configuration object.

Return
Resources!: a Resources instance for the application's package

See Also

getString

added in API level 1
fun getString(resId: Int): String

Returns a localized string from the application's package's default string table.

Parameters
resId Int: Resource id for the string
Return
String: The string data associated with the resource, stripped of styled text information. This value will never be null.

getString

added in API level 1
fun getString(resId: Int, vararg formatArgs: Any!): String

Returns a localized formatted string from the application's package's default string table, substituting the format arguments as defined in java.util.Formatter and java.lang.String#format.

Parameters
resId Int: Resource id for the format string
formatArgs Int: The format arguments that will be used for substitution.
Return
String: The string data associated with the resource, formatted and stripped of styled text information. This value will never be null.

registerComponentCallbacks

added in API level 14
open fun registerComponentCallbacks(callback: ComponentCallbacks!): Unit

Add a new ComponentCallbacks to the base application of the Context, which will be called at the same times as the ComponentCallbacks methods of activities and other components are called. Note that you must be sure to use unregisterComponentCallbacks when appropriate in the future; this will not be removed for you.

Parameters
callback ComponentCallbacks!: The interface to call. This can be either a ComponentCallbacks or ComponentCallbacks2 interface.

fileList

added in API level 1
abstract fun fileList(): Array<String!>!

Returns an array of strings naming the private files associated with this Context's application package.

Return
Array<String!>!: Array of strings naming the private files.

setTheme

added in API level 1
abstract fun setTheme(resid: Int): Unit

Set the base theme for this context. Note that this should be called before any views are instantiated in the Context (for example before calling android.app.Activity#setContentView or android.view.LayoutInflater#inflate).

Parameters
resid Int: The style resource describing the theme.

unregisterReceiver

added in API level 1
abstract fun unregisterReceiver(receiver: BroadcastReceiver!): Unit

Unregister a previously registered BroadcastReceiver. All filters that have been registered for this BroadcastReceiver will be removed.

Parameters
receiver BroadcastReceiver!: The BroadcastReceiver to unregister.

enforcePermission

added in API level 1
abstract fun enforcePermission(permission: String, pid: Int, uid: Int, message: String?): Unit

If the given permission is not allowed for a particular process and user ID running in the system, throw a SecurityException.

Parameters
permission String: The name of the permission being checked. This value must never be null.
pid String: The process ID being checked against. Must be > 0.
uid String: The user ID being checked against. A uid of 0 is the root user, which will pass every permission check.
message String: A message to include in the exception if it is thrown. This value may be null.

openFileOutput

added in API level 1
abstract fun openFileOutput(name: String!, mode: Int): FileOutputStream!

Open a private file associated with this Context's application package for writing. Creates the file if it doesn't already exist.

No additional permissions are required for the calling app to read or write the returned file.

Parameters
name String!: The name of the file to open; can not contain path separators.
mode String!: Operating mode. Value is either 0 or a combination of android.content.Context#MODE_PRIVATE, android.content.Context#MODE_WORLD_READABLE, android.content.Context#MODE_WORLD_WRITEABLE, and android.content.Context#MODE_APPEND
Return
FileOutputStream!: The resulting FileOutputStream.

sendStickyOrderedBroadcast

added in API level 5
abstract fun sendStickyOrderedBroadcast(intent: Intent!, resultReceiver: BroadcastReceiver!, scheduler: Handler?, initialCode: Int, initialData: String?, initialExtras: Bundle?): Unit

Version of sendStickyBroadcast that allows you to receive data back from the broadcast. This is accomplished by supplying your own BroadcastReceiver when calling, which will be treated as a final receiver at the end of the broadcast -- its BroadcastReceiver#onReceive method will be called with the result values collected from the other receivers. The broadcast will be serialized in the same way as calling sendOrderedBroadcast(android.content.Intent,java.lang.String).

Like sendBroadcast(android.content.Intent), this method is asynchronous; it will return before resultReceiver.onReceive() is called. Note that the sticky data stored is only the data you initially supply to the broadcast, not the result of any changes made by the receivers.

See BroadcastReceiver for more information on Intent broadcasts.
Requires android.Manifest.permission#BROADCAST_STICKY

Parameters
intent Intent!: The Intent to broadcast; all receivers matching this Intent will receive the broadcast.
resultReceiver Intent!: Your own BroadcastReceiver to treat as the final receiver of the broadcast.
scheduler Intent!: A custom Handler with which to schedule the resultReceiver callback; if null it will be scheduled in the Context's main thread. This value may be null.
initialCode Intent!: An initial value for the result code. Often Activity.RESULT_OK.
initialData Intent!: An initial value for the result data. Often null. This value may be null.
initialExtras Intent!: An initial value for the result extras. Often null. This value may be null.

createConfigurationContext

added in API level 17
abstract fun createConfigurationContext(overrideConfiguration: Configuration): Context!

Return a new Context object for the current Context but whose resources are adjusted to match the given Configuration. Each call to this method returns a new instance of a Context object; Context objects are not shared, however common state (ClassLoader, other Resources for the same configuration) may be so the Context itself can be fairly lightweight.

Parameters
overrideConfiguration Configuration: A Configuration specifying what values to modify in the base Configuration of the original Context's resources. If the base configuration changes (such as due to an orientation change), the resources of this context will also change except for those that have been explicitly overridden with a value here. This value must never be null.
Return
Context!: A Context with the given configuration override.

getFilesDir

added in API level 1
abstract fun getFilesDir(): File!

Returns the absolute path to the directory on the filesystem where files created with openFileOutput are stored.

The returned path may change over time if the calling app is moved to an adopted storage device, so only relative paths should be persisted.

No additional permissions are required for the calling app to read or write files under the returned path.

Return
File!: The path of the directory holding application files.

sendBroadcast

added in API level 1
abstract fun sendBroadcast(intent: Intent!): Unit

Broadcast the given intent to all interested BroadcastReceivers. This call is asynchronous; it returns immediately, and you will continue executing while the receivers are run. No results are propagated from receivers and receivers can not abort the broadcast. If you want to allow receivers to propagate results or abort the broadcast, you must send an ordered broadcast using sendOrderedBroadcast(android.content.Intent,java.lang.String).

See BroadcastReceiver for more information on Intent broadcasts.

Parameters
intent Intent!: The Intent to broadcast; all receivers matching this Intent will receive the broadcast.

sendBroadcast

added in API level 1
abstract fun sendBroadcast(intent: Intent!, receiverPermission: String?): Unit

Broadcast the given intent to all interested BroadcastReceivers, allowing an optional required permission to be enforced. This call is asynchronous; it returns immediately, and you will continue executing while the receivers are run. No results are propagated from receivers and receivers can not abort the broadcast. If you want to allow receivers to propagate results or abort the broadcast, you must send an ordered broadcast using sendOrderedBroadcast(android.content.Intent,java.lang.String).

See BroadcastReceiver for more information on Intent broadcasts.

Parameters
intent Intent!: The Intent to broadcast; all receivers matching this Intent will receive the broadcast.
receiverPermission Intent!: (optional) String naming a permission that a receiver must hold in order to receive your broadcast. If null, no permission is required. This value may be null.

getText

added in API level 1
fun getText(resId: Int): CharSequence

Return a localized, styled CharSequence from the application's package's default string table.

Parameters
resId Int: Resource id for the CharSequence text
Return
CharSequence: This value will never be null.

sendOrderedBroadcastAsUser

added in API level 17
abstract fun sendOrderedBroadcastAsUser(intent: Intent!, user: UserHandle!, receiverPermission: String?, resultReceiver: BroadcastReceiver!, scheduler: Handler?, initialCode: Int, initialData: String?, initialExtras: Bundle?): Unit

Version of sendOrderedBroadcast(android.content.Intent,java.lang.String,android.content.BroadcastReceiver,android.os.Handler,int,java.lang.String,android.os.Bundle) that allows you to specify the user the broadcast will be sent to. This is not available to applications that are not pre-installed on the system image.

See BroadcastReceiver for more information on Intent broadcasts.
Requires android.Manifest.permission.INTERACT_ACROSS_USERS

Parameters
intent Intent!: The Intent to broadcast; all receivers matching this Intent will receive the broadcast.
user Intent!: UserHandle to send the intent to.
receiverPermission Intent!: String naming a permissions that a receiver must hold in order to receive your broadcast. If null, no permission is required. This value may be null.
resultReceiver Intent!: Your own BroadcastReceiver to treat as the final receiver of the broadcast.
scheduler Intent!: A custom Handler with which to schedule the resultReceiver callback; if null it will be scheduled in the Context's main thread. This value may be null.
initialCode Intent!: An initial value for the result code. Often Activity.RESULT_OK.
initialData Intent!: An initial value for the result data. Often null. This value may be null.
initialExtras Intent!: An initial value for the result extras. Often null. This value may be null.

grantUriPermission

added in API level 1
abstract fun grantUriPermission(toPackage: String!, uri: Uri!, modeFlags: Int): Unit

Grant permission to access a specific Uri to another package, regardless of whether that package has general permission to access the Uri's content provider. This can be used to grant specific, temporary permissions, typically in response to user interaction (such as the user opening an attachment that you would like someone else to display).

Normally you should use Intent#FLAG_GRANT_READ_URI_PERMISSION or Intent#FLAG_GRANT_WRITE_URI_PERMISSION with the Intent being used to start an activity instead of this function directly. If you use this function directly, you should be sure to call revokeUriPermission when the target should no longer be allowed to access it.

To succeed, the content provider owning the Uri must have set the grantUriPermissions attribute in its manifest or included the &lt;grant-uri-permissions&gt; tag.

Parameters
toPackage String!: The package you would like to allow to access the Uri.
uri String!: The Uri you would like to grant access to.
modeFlags String!: The desired access modes. Value is either 0 or a combination of android.content.Intent#FLAG_GRANT_READ_URI_PERMISSION, android.content.Intent#FLAG_GRANT_WRITE_URI_PERMISSION, android.content.Intent#FLAG_GRANT_PERSISTABLE_URI_PERMISSION, and android.content.Intent#FLAG_GRANT_PREFIX_URI_PERMISSION

enforceCallingUriPermission

added in API level 1
abstract fun enforceCallingUriPermission(uri: Uri!, modeFlags: Int, message: String!): Unit

If the calling process and user ID has not been granted permission to access a specific URI, throw SecurityException. This is basically the same as calling enforceUriPermission(android.net.Uri,int,int,int,java.lang.String) with the pid and uid returned by and . One important difference is that if you are not currently processing an IPC, this function will always throw a SecurityException.

Parameters
uri Uri!: The uri that is being checked.
modeFlags Uri!: The access modes to enforce. Value is either 0 or a combination of android.content.Intent#FLAG_GRANT_READ_URI_PERMISSION, and android.content.Intent#FLAG_GRANT_WRITE_URI_PERMISSION
message Uri!: A message to include in the exception if it is thrown.

isRestricted

added in API level 4
open fun isRestricted(): Boolean

Indicates whether this Context is restricted.

Return
Boolean: true if this Context is restricted, false otherwise.

getCacheDir

added in API level 1
abstract fun getCacheDir(): File!

Returns the absolute path to the application specific cache directory on the filesystem.

The system will automatically delete files in this directory as disk space is needed elsewhere on the device. The system will always delete older files first, as reported by File#lastModified(). If desired, you can exert more control over how files are deleted using StorageManager#setCacheBehaviorGroup(File, boolean) and StorageManager#setCacheBehaviorTombstone(File, boolean).

Apps are strongly encouraged to keep their usage of cache space below the quota returned by StorageManager#getCacheQuotaBytes(java.util.UUID). If your app goes above this quota, your cached files will be some of the first to be deleted when additional disk space is needed. Conversely, if your app stays under this quota, your cached files will be some of the last to be deleted when additional disk space is needed.

Note that your cache quota will change over time depending on how frequently the user interacts with your app, and depending on how much system-wide disk space is used.

The returned path may change over time if the calling app is moved to an adopted storage device, so only relative paths should be persisted.

Apps require no extra permissions to read or write to the returned path, since this path lives in their private storage.

Return
File!: The path of the directory holding application cache files.

clearWallpaper

added in API level 1
abstract fun clearWallpaper(): Unit

sendStickyOrderedBroadcastAsUser

added in API level 17
abstract fun sendStickyOrderedBroadcastAsUser(intent: Intent!, user: UserHandle!, resultReceiver: BroadcastReceiver!, scheduler: Handler?, initialCode: Int, initialData: String?, initialExtras: Bundle?): Unit

Version of sendStickyOrderedBroadcast(android.content.Intent,android.content.BroadcastReceiver,android.os.Handler,int,java.lang.String,android.os.Bundle) that allows you to specify the user the broadcast will be sent to. This is not available to applications that are not pre-installed on the system image.

See BroadcastReceiver for more information on Intent broadcasts.
Requires android.Manifest.permission.INTERACT_ACROSS_USERS and android.Manifest.permission#BROADCAST_STICKY

Parameters
intent Intent!: The Intent to broadcast; all receivers matching this Intent will receive the broadcast.
user Intent!: UserHandle to send the intent to.
resultReceiver Intent!: Your own BroadcastReceiver to treat as the final receiver of the broadcast.
scheduler Intent!: A custom Handler with which to schedule the resultReceiver callback; if null it will be scheduled in the Context's main thread. This value may be null.
initialCode Intent!: An initial value for the result code. Often Activity.RESULT_OK.
initialData Intent!: An initial value for the result data. Often null. This value may be null.
initialExtras Intent!: An initial value for the result extras. Often null. This value may be null.

startActivity

added in API level 1
abstract fun startActivity(intent: Intent!): Unit

Same as startActivity(android.content.Intent,android.os.Bundle) with no options specified.

Parameters
intent Intent!: The description of the activity to start.
Exceptions
android.content.ActivityNotFoundException   `

startActivity

added in API level 16
abstract fun startActivity(intent: Intent!, options: Bundle?): Unit

Launch a new activity. You will not receive any information about when the activity exits.

Note that if this method is being called from outside of an android.app.Activity Context, then the Intent must include the Intent#FLAG_ACTIVITY_NEW_TASK launch flag. This is because, without being started from an existing Activity, there is no existing task in which to place the new activity and thus it needs to be placed in its own separate task.

This method throws ActivityNotFoundException if there was no Activity found to run the given Intent.

Parameters
intent Intent!: The description of the activity to start.
options Intent!: Additional options for how the Activity should be started. May be null if there are no options. See android.app.ActivityOptions for how to build the Bundle supplied here; there are no supported definitions for building it manually. This value may be null.
Exceptions
android.content.ActivityNotFoundException  

getPackageManager

added in API level 1
abstract fun getPackageManager(): PackageManager!

Return PackageManager instance to find global package information.

getOpPackageName

added in API level Q
open fun getOpPackageName(): String!

Return the package name that should be used for android.app.AppOpsManager calls from this context, so that app ops manager's uid verification will work with the name.

This is not generally intended for third party application developers.

openOrCreateDatabase

added in API level 1
abstract fun openOrCreateDatabase(name: String!, mode: Int, factory: SQLiteDatabase.CursorFactory!): SQLiteDatabase!

Open a new private SQLiteDatabase associated with this Context's application package. Create the database file if it doesn't exist.

Parameters
name String!: The name (unique in the application package) of the database.
mode String!: Operating mode. Value is either 0 or a combination of android.content.Context#MODE_PRIVATE, android.content.Context#MODE_WORLD_READABLE, android.content.Context#MODE_WORLD_WRITEABLE, android.content.Context#MODE_ENABLE_WRITE_AHEAD_LOGGING, and android.content.Context#MODE_NO_LOCALIZED_COLLATORS
factory String!: An optional factory class that is called to instantiate a cursor when query is called.
Return
SQLiteDatabase!: The contents of a newly created database with the given name.
Exceptions
android.database.sqlite.SQLiteException if the database file could not be opened.

openOrCreateDatabase

added in API level 11
abstract fun openOrCreateDatabase(name: String!, mode: Int, factory: SQLiteDatabase.CursorFactory!, errorHandler: DatabaseErrorHandler?): SQLiteDatabase!

Open a new private SQLiteDatabase associated with this Context's application package. Creates the database file if it doesn't exist.

Accepts input param: a concrete instance of DatabaseErrorHandler to be used to handle corruption when sqlite reports database corruption.

Parameters
name String!: The name (unique in the application package) of the database.
mode String!: Operating mode. Value is either 0 or a combination of android.content.Context#MODE_PRIVATE, android.content.Context#MODE_WORLD_READABLE, android.content.Context#MODE_WORLD_WRITEABLE, android.content.Context#MODE_ENABLE_WRITE_AHEAD_LOGGING, and android.content.Context#MODE_NO_LOCALIZED_COLLATORS
factory String!: An optional factory class that is called to instantiate a cursor when query is called.
errorHandler String!: the DatabaseErrorHandler to be used when sqlite reports database corruption. if null, android.database.DefaultDatabaseErrorHandler is assumed. This value may be null.
Return
SQLiteDatabase!: The contents of a newly created database with the given name.
Exceptions
android.database.sqlite.SQLiteException if the database file could not be opened.

deleteFile

added in API level 1
abstract fun deleteFile(name: String!): Boolean

Delete the given private file associated with this Context's application package.

Parameters
name String!: The name of the file to delete; can not contain path separators.
Return
Boolean: true if the file was successfully deleted; else false.

startService

added in API level 1
abstract fun startService(service: Intent!): ComponentName?

Request that a given application service be started. The Intent should either contain the complete class name of a specific service implementation to start, or a specific package name to target. If the Intent is less specified, it logs a warning about this. In this case any of the multiple matching services may be used. If this service is not already running, it will be instantiated and started (creating a process for it if needed); if it is running then it remains running.

Every call to this method will result in a corresponding call to the target service's android.app.Service#onStartCommand method, with the intent given here. This provides a convenient way to submit jobs to a service without having to bind and call on to its interface.

Using startService() overrides the default service lifetime that is managed by bindService: it requires the service to remain running until stopService is called, regardless of whether any clients are connected to it. Note that calls to startService() do not nest: no matter how many times you call startService(), a single call to stopService will stop it.

The system attempts to keep running services around as much as possible. The only time they should be stopped is if the current foreground application is using so many resources that the service needs to be killed. If any errors happen in the service's process, it will automatically be restarted.

This function will throw SecurityException if you do not have permission to start the given service.

Note: Each call to startService() results in significant work done by the system to manage service lifecycle surrounding the processing of the intent, which can take multiple milliseconds of CPU time. Due to this cost, startService() should not be used for frequent intent delivery to a service, and only for scheduling significant work. Use bound services for high frequency calls.

Parameters
service Intent!: Identifies the service to be started. The Intent must be fully explicit (supplying a component name). Additional values may be included in the Intent extras to supply arguments along with this specific start call.
Return
ComponentName?: If the service is being started or is already running, the ComponentName of the actual service that was started is returned; else if the service does not exist null is returned.
Exceptions
java.lang.SecurityException If the caller does not have permission to access the service or the service can not be found.
java.lang.IllegalStateException If the application is in a state where the service can not be started (such as not in the foreground in a state when services are allowed).

revokeUriPermission

added in API level 1
abstract fun revokeUriPermission(uri: Uri!, modeFlags: Int): Unit

Remove all permissions to access a particular content provider Uri that were previously added with grantUriPermission or any other mechanism. The given Uri will match all previously granted Uris that are the same or a sub-path of the given Uri. That is, revoking "content://foo/target" will revoke both "content://foo/target" and "content://foo/target/sub", but not "content://foo". It will not remove any prefix grants that exist at a higher level.

Prior to android.os.Build.VERSION_CODES#LOLLIPOP, if you did not have regular permission access to a Uri, but had received access to it through a specific Uri permission grant, you could not revoke that grant with this function and a SecurityException would be thrown. As of android.os.Build.VERSION_CODES#LOLLIPOP, this function will not throw a security exception, but will remove whatever permission grants to the Uri had been given to the app (or none).

Unlike revokeUriPermission(java.lang.String,android.net.Uri,int), this method impacts all permission grants matching the given Uri, for any package they had been granted to, through any mechanism this had happened (such as indirectly through the clipboard, activity launch, service start, etc). That means this can be potentially dangerous to use, as it can revoke grants that another app could be strongly expecting to stick around.

Parameters
uri Uri!: The Uri you would like to revoke access to.
modeFlags Uri!: The access modes to revoke. Value is either 0 or a combination of android.content.Intent#FLAG_GRANT_READ_URI_PERMISSION, and android.content.Intent#FLAG_GRANT_WRITE_URI_PERMISSION

revokeUriPermission

added in API level 26
abstract fun revokeUriPermission(toPackage: String!, uri: Uri!, modeFlags: Int): Unit

Remove permissions to access a particular content provider Uri that were previously added with grantUriPermission for a specific target package. The given Uri will match all previously granted Uris that are the same or a sub-path of the given Uri. That is, revoking "content://foo/target" will revoke both "content://foo/target" and "content://foo/target/sub", but not "content://foo". It will not remove any prefix grants that exist at a higher level.

Unlike revokeUriPermission(android.net.Uri,int), this method will only revoke permissions that had been explicitly granted through grantUriPermission and only for the package specified. Any matching grants that have happened through other mechanisms (clipboard, activity launching, service starting, etc) will not be removed.

Parameters
toPackage String!: The package you had previously granted access to.
uri String!: The Uri you would like to revoke access to.
modeFlags String!: The access modes to revoke. Value is either 0 or a combination of android.content.Intent#FLAG_GRANT_READ_URI_PERMISSION, and android.content.Intent#FLAG_GRANT_WRITE_URI_PERMISSION

getColor

added in API level 23
fun getColor(id: Int): Int

Returns a color associated with a particular resource ID and styled for the current theme.

Parameters
id Int: The desired resource identifier, as generated by the aapt tool. This integer encodes the package, type, and resource entry. The value 0 is an invalid identifier.
Return
Int: A single color value in the form 0xAARRGGBB.
Exceptions
android.content.res.Resources.NotFoundException if the given ID does not exist.

moveDatabaseFrom

added in API level 24
abstract fun moveDatabaseFrom(sourceContext: Context!, name: String!): Boolean

Move an existing database file from the given source storage context to this context. This is typically used to migrate data between storage locations after an upgrade, such as migrating to device protected storage.

The database must be closed before being moved.

Parameters
sourceContext Context!: The source context which contains the existing database to move.
name Context!: The name of the database file.
Return
Boolean: true if the move was successful or if the database didn't exist in the source context, otherwise false.

startInstrumentation

added in API level 1
abstract fun startInstrumentation(className: ComponentName, profileFile: String?, arguments: Bundle?): Boolean

Start executing an android.app.Instrumentation class. The given Instrumentation component will be run by killing its target application (if currently running), starting the target process, instantiating the instrumentation component, and then letting it drive the application.

This function is not synchronous -- it returns as soon as the instrumentation has started and while it is running.

Instrumentation is normally only allowed to run against a package that is either unsigned or signed with a signature that the the instrumentation package is also signed with (ensuring the target trusts the instrumentation).

Parameters
className ComponentName: Name of the Instrumentation component to be run. This value must never be null.
profileFile ComponentName: Optional path to write profiling data as the instrumentation runs, or null for no profiling. This value may be null.
arguments ComponentName: Additional optional arguments to pass to the instrumentation, or null. This value may be null.
Return
Boolean: true if the instrumentation was successfully started, else false if it could not be found.

sendOrderedBroadcast

added in API level 1
abstract fun sendOrderedBroadcast(intent: Intent!, receiverPermission: String?): Unit

Broadcast the given intent to all interested BroadcastReceivers, delivering them one at a time to allow more preferred receivers to consume the broadcast before it is delivered to less preferred receivers. This call is asynchronous; it returns immediately, and you will continue executing while the receivers are run.

See BroadcastReceiver for more information on Intent broadcasts.

Parameters
intent Intent!: The Intent to broadcast; all receivers matching this Intent will receive the broadcast.
receiverPermission Intent!: (optional) String naming a permissions that a receiver must hold in order to receive your broadcast. If null, no permission is required. This value may be null.

sendOrderedBroadcast

added in API level 1
abstract fun sendOrderedBroadcast(intent: Intent, receiverPermission: String?, resultReceiver: BroadcastReceiver?, scheduler: Handler?, initialCode: Int, initialData: String?, initialExtras: Bundle?): Unit

Version of sendBroadcast(android.content.Intent) that allows you to receive data back from the broadcast. This is accomplished by supplying your own BroadcastReceiver when calling, which will be treated as a final receiver at the end of the broadcast -- its BroadcastReceiver#onReceive method will be called with the result values collected from the other receivers. The broadcast will be serialized in the same way as calling sendOrderedBroadcast(android.content.Intent,java.lang.String).

Like sendBroadcast(android.content.Intent), this method is asynchronous; it will return before resultReceiver.onReceive() is called.

See BroadcastReceiver for more information on Intent broadcasts.

Parameters
intent Intent: The Intent to broadcast; all receivers matching this Intent will receive the broadcast. This value must never be null.
receiverPermission Intent: String naming a permissions that a receiver must hold in order to receive your broadcast. If null, no permission is required. This value may be null.
resultReceiver Intent: Your own BroadcastReceiver to treat as the final receiver of the broadcast. This value may be null.
scheduler Intent: A custom Handler with which to schedule the resultReceiver callback; if null it will be scheduled in the Context's main thread. This value may be null.
initialCode Intent: An initial value for the result code. Often Activity.RESULT_OK.
initialData Intent: An initial value for the result data. Often null. This value may be null.
initialExtras Intent: An initial value for the result extras. Often null. This value may be null.

bindIsolatedService

added in API level Q
open fun bindIsolatedService(service: Intent!, conn: ServiceConnection, flags: Int, instanceName: String): Boolean

Variation of bindService that, in the specific case of isolated services, allows the caller to generate multiple instances of a service from a single component declaration.

Parameters
service Intent!: Identifies the service to connect to. The Intent must specify an explicit component name.
conn Intent!: Receives information as the service is started and stopped. This must be a valid ServiceConnection object; it must not be null. This value must never be null.
flags Intent!: Operation options for the binding as per bindService. Value is either 0 or a combination of android.content.Context#BIND_AUTO_CREATE, android.content.Context#BIND_DEBUG_UNBIND, android.content.Context#BIND_NOT_FOREGROUND, android.content.Context#BIND_ABOVE_CLIENT, android.content.Context#BIND_ALLOW_OOM_MANAGEMENT, android.content.Context#BIND_WAIVE_PRIORITY, android.content.Context#BIND_IMPORTANT, and android.content.Context#BIND_ADJUST_WITH_ACTIVITY
instanceName Intent!: Unique identifier for the service instance. Each unique name here will result in a different service instance being created. This value must never be null.
Return
Boolean: Returns success of binding as per bindService.
Exceptions
java.lang.SecurityException If the caller does not have permission to access the service

See Also

unbindService

added in API level 1
abstract fun unbindService(conn: ServiceConnection): Unit

Disconnect from an application service. You will no longer receive calls as the service is restarted, and the service is now allowed to stop at any time.

Parameters
conn ServiceConnection: The connection interface previously supplied to bindService(). This parameter must not be null. This value must never be null.

See Also

getApplicationInfo

added in API level 4
abstract fun getApplicationInfo(): ApplicationInfo!

Return the full application info for this context's package.

getWallpaperDesiredMinimumHeight

added in API level 1
abstract fun getWallpaperDesiredMinimumHeight(): Int

createDisplayContext

added in API level 17
abstract fun createDisplayContext(display: Display): Context!

Return a new Context object for the current Context but whose resources are adjusted to match the metrics of the given Display. Each call to this method returns a new instance of a Context object; Context objects are not shared, however common state (ClassLoader, other Resources for the same configuration) may be so the Context itself can be fairly lightweight. The returned display Context provides a WindowManager (see getSystemService(java.lang.String)) that is configured to show windows on the given display. The WindowManager's WindowManager#getDefaultDisplay method can be used to retrieve the Display from the returned Context.

Parameters
display Display: A Display object specifying the display for whose metrics the Context's resources should be tailored and upon which new windows should be shown. This value must never be null.
Return
Context!: A Context for the display.

createContextForSplit

added in API level 26
abstract fun createContextForSplit(splitName: String!): Context!

Return a new Context object for the given split name. The new Context has a ClassLoader and Resources object that can access the split's and all of its dependencies' code/resources. Each call to this method returns a new instance of a Context object; Context objects are not shared, however common state (ClassLoader, other Resources for the same split) may be so the Context itself can be fairly lightweight.

Parameters
splitName String!: The name of the split to include, as declared in the split's AndroidManifest.xml.
Return
Context!: A Context with the given split's code and/or resources loaded.

getTheme

added in API level 1
abstract fun getTheme(): Resources.Theme!

Return the Theme object associated with this Context.

getPackageName

added in API level 1
abstract fun getPackageName(): String!

Return the name of this application's package.

getContentResolver

added in API level 1
abstract fun getContentResolver(): ContentResolver!

Return a ContentResolver instance for your application's package.

getObbDirs

added in API level 19
abstract fun getObbDirs(): Array<File!>!

Returns absolute paths to application-specific directories on all shared/external storage devices where the application's OBB files (if there are any) can be found. Note if the application does not have any OBB files, these directories may not exist.

This is like getFilesDir() in that these files will be deleted when the application is uninstalled, however there are some important differences:

Shared storage devices returned here are considered a stable part of the device, including physical media slots under a protective cover. The returned paths do not include transient devices, such as USB flash drives connected to handheld devices.

An application may store data on any or all of the returned devices. For example, an app may choose to store large files on the device with the most available space, as measured by StatFs.

No additional permissions are required for the calling app to read or write files under the returned path. Write access outside of these paths on secondary external storage devices is not available.

Return
Array<File!>!: the absolute paths to application-specific directories. Some individual paths may be null if that shared storage is not currently available. The first path returned is the same as getObbDir()

obtainStyledAttributes

added in API level 1
fun obtainStyledAttributes(attrs: IntArray): TypedArray

Retrieve styled attribute information in this Context's theme. See android.content.res.Resources.Theme#obtainStyledAttributes(int[]) for more information.

Parameters
attrs IntArray: This value must never be null.
Return
TypedArray: This value will never be null.

obtainStyledAttributes

added in API level 1
fun obtainStyledAttributes(resid: Int, attrs: IntArray): TypedArray

Retrieve styled attribute information in this Context's theme. See android.content.res.Resources.Theme#obtainStyledAttributes(int, int[]) for more information.

Parameters
attrs Int: This value must never be null.
Return
TypedArray: This value will never be null.

obtainStyledAttributes

added in API level 1
fun obtainStyledAttributes(set: AttributeSet?, attrs: IntArray): TypedArray

Retrieve styled attribute information in this Context's theme. See android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int) for more information.

Parameters
set AttributeSet?: This value may be null.
attrs AttributeSet?: This value must never be null.
Return
TypedArray: This value will never be null.

obtainStyledAttributes

added in API level 1
fun obtainStyledAttributes(set: AttributeSet?, attrs: IntArray, defStyleAttr: Int, defStyleRes: Int): TypedArray

Retrieve styled attribute information in this Context's theme. See android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int) for more information.

Parameters
set AttributeSet?: This value may be null.
attrs AttributeSet?: This value must never be null.
Return
TypedArray: This value will never be null.

enforceCallingOrSelfUriPermission

added in API level 1
abstract fun enforceCallingOrSelfUriPermission(uri: Uri!, modeFlags: Int, message: String!): Unit

If the calling process of an IPC or you has not been granted permission to access a specific URI, throw SecurityException. This is the same as , except it grants your own permissions if you are not currently processing an IPC. Use with care!

Parameters
uri Uri!: The uri that is being checked.
modeFlags Uri!: The access modes to enforce. Value is either 0 or a combination of android.content.Intent#FLAG_GRANT_READ_URI_PERMISSION, and android.content.Intent#FLAG_GRANT_WRITE_URI_PERMISSION
message Uri!: A message to include in the exception if it is thrown.

moveSharedPreferencesFrom

added in API level 24
abstract fun moveSharedPreferencesFrom(sourceContext: Context!, name: String!): Boolean

Move an existing shared preferences file from the given source storage context to this context. This is typically used to migrate data between storage locations after an upgrade, such as moving to device protected storage.

Parameters
sourceContext Context!: The source context which contains the existing shared preferences to move.
name Context!: The name of the shared preferences file.
Return
Boolean: true if the move was successful or if the shared preferences didn't exist in the source context, otherwise false.

getExternalMediaDirs

added in API level 21
abstract fun getExternalMediaDirs(): Array<File!>!

Returns absolute paths to application-specific directories on all shared/external storage devices where the application can place media files. These files are scanned and made available to other apps through MediaStore.

This is like getExternalFilesDirs in that these files will be deleted when the application is uninstalled, however there are some important differences:

Shared storage devices returned here are considered a stable part of the device, including physical media slots under a protective cover. The returned paths do not include transient devices, such as USB flash drives connected to handheld devices.

An application may store data on any or all of the returned devices. For example, an app may choose to store large files on the device with the most available space, as measured by StatFs.

No additional permissions are required for the calling app to read or write files under the returned path. Write access outside of these paths on secondary external storage devices is not available.

The returned paths may change over time if different shared storage media is inserted, so only relative paths should be persisted.

Return
Array<File!>!: the absolute paths to application-specific directories. Some individual paths may be null if that shared storage is not currently available.

checkCallingPermission

added in API level 1
abstract fun checkCallingPermission(permission: String): Int

Determine whether the calling process of an IPC you are handling has been granted a particular permission. This is basically the same as calling checkPermission(java.lang.String,int,int) with the pid and uid returned by android.os.Binder#getCallingPid and android.os.Binder#getCallingUid. One important difference is that if you are not currently processing an IPC, this function will always fail. This is done to protect against accidentally leaking permissions; you can use checkCallingOrSelfPermission to avoid this protection.

Parameters
permission String: The name of the permission being checked. This value must never be null.
Return
Int: PackageManager#PERMISSION_GRANTED if the calling pid/uid is allowed that permission, or PackageManager#PERMISSION_DENIED if it is not. Value is android.content.pm.PackageManager#PERMISSION_GRANTED, or android.content.pm.PackageManager#PERMISSION_DENIED

getExternalCacheDirs

added in API level 19
abstract fun getExternalCacheDirs(): Array<File!>!

Returns absolute paths to application-specific directories on all shared/external storage devices where the application can place cache files it owns. These files are internal to the application, and not typically visible to the user as media.

This is like getCacheDir() in that these files will be deleted when the application is uninstalled, however there are some important differences:

If a shared storage device is emulated (as determined by Environment#isExternalStorageEmulated(File)), it's contents are backed by a private user data partition, which means there is little benefit to storing data here instead of the private directory returned by getCacheDir().

Shared storage devices returned here are considered a stable part of the device, including physical media slots under a protective cover. The returned paths do not include transient devices, such as USB flash drives connected to handheld devices.

An application may store data on any or all of the returned devices. For example, an app may choose to store large files on the device with the most available space, as measured by StatFs.

No additional permissions are required for the calling app to read or write files under the returned path. Write access outside of these paths on secondary external storage devices is not available.

The returned paths may change over time if different shared storage media is inserted, so only relative paths should be persisted.

Return
Array<File!>!: the absolute paths to application-specific directories. Some individual paths may be null if that shared storage is not currently available. The first path returned is the same as getExternalCacheDir().

sendStickyBroadcast

added in API level 1
abstract fun sendStickyBroadcast(intent: Intent!): Unit

Perform a sendBroadcast(android.content.Intent) that is "sticky," meaning the Intent you are sending stays around after the broadcast is complete, so that others can quickly retrieve that data through the return value of registerReceiver(android.content.BroadcastReceiver,android.content.IntentFilter). In all other ways, this behaves the same as sendBroadcast(android.content.Intent).
Requires android.Manifest.permission#BROADCAST_STICKY

Parameters
intent Intent!: The Intent to broadcast; all receivers matching this Intent will receive the broadcast, and the Intent will be held to be re-broadcast to future receivers.

enforceCallingPermission

added in API level 1
abstract fun enforceCallingPermission(permission: String, message: String?): Unit

If the calling process of an IPC you are handling has not been granted a particular permission, throw a SecurityException. This is basically the same as calling enforcePermission(java.lang.String,int,int,java.lang.String) with the pid and uid returned by android.os.Binder#getCallingPid and android.os.Binder#getCallingUid. One important difference is that if you are not currently processing an IPC, this function will always throw the SecurityException. This is done to protect against accidentally leaking permissions; you can use enforceCallingOrSelfPermission to avoid this protection.

Parameters
permission String: The name of the permission being checked. This value must never be null.
message String: A message to include in the exception if it is thrown. This value may be null.

peekWallpaper

added in API level 1
abstract fun peekWallpaper(): Drawable!

getSystemService

added in API level 1
abstract fun getSystemService(name: String): Any!

Return the handle to a system-level service by name. The class of the returned object varies by the requested name. Currently available names are: WINDOW_SERVICE ("window") The top-level window manager in which you can place custom windows. The returned object is a android.view.WindowManager. LAYOUT_INFLATER_SERVICE ("layout_inflater") A android.view.LayoutInflater for inflating layout resources in this context. ACTIVITY_SERVICE ("activity") A android.app.ActivityManager for interacting with the global activity state of the system. POWER_SERVICE ("power") A android.os.PowerManager for controlling power management. ALARM_SERVICE ("alarm") A android.app.AlarmManager for receiving intents at the time of your choosing. NOTIFICATION_SERVICE ("notification") A android.app.NotificationManager for informing the user of background events. KEYGUARD_SERVICE ("keyguard") A android.app.KeyguardManager for controlling keyguard. LOCATION_SERVICE ("location") A android.location.LocationManager for controlling location (e.g., GPS) updates. SEARCH_SERVICE ("search") A android.app.SearchManager for handling search. VIBRATOR_SERVICE ("vibrator") A android.os.Vibrator for interacting with the vibrator hardware. CONNECTIVITY_SERVICE ("connection") A ConnectivityManager for handling management of network connections. IPSEC_SERVICE ("ipsec") A IpSecManager for managing IPSec on sockets and networks. WIFI_SERVICE ("wifi") A WifiManager for management of Wi-Fi connectivity. On releases before NYC, it should only be obtained from an application context, and not from any other derived context to avoid memory leaks within the calling process. WIFI_AWARE_SERVICE ("wifiaware") A WifiAwareManager for management of Wi-Fi Aware discovery and connectivity. WIFI_P2P_SERVICE ("wifip2p") A WifiP2pManager for management of Wi-Fi Direct connectivity. INPUT_METHOD_SERVICE ("input_method") An InputMethodManager for management of input methods. UI_MODE_SERVICE ("uimode") An android.app.UiModeManager for controlling UI modes. DOWNLOAD_SERVICE ("download") A android.app.DownloadManager for requesting HTTP downloads BATTERY_SERVICE ("batterymanager") A android.os.BatteryManager for managing battery state JOB_SCHEDULER_SERVICE ("taskmanager") A android.app.job.JobScheduler for managing scheduled tasks NETWORK_STATS_SERVICE ("netstats") A NetworkStatsManager for querying network usage statistics. HARDWARE_PROPERTIES_SERVICE ("hardware_properties") A android.os.HardwarePropertiesManager for accessing hardware properties.

Note: System services obtained via this API may be closely associated with the Context in which they are obtained from. In general, do not share the service objects between various different contexts (Activities, Applications, Services, Providers, etc.)

Note: Instant apps, for which PackageManager#isInstantApp() returns true, don't have access to the following system services: DEVICE_POLICY_SERVICE, FINGERPRINT_SERVICE, KEYGUARD_SERVICE, SHORTCUT_SERVICE, USB_SERVICE, WALLPAPER_SERVICE, WIFI_P2P_SERVICE, WIFI_SERVICE, WIFI_AWARE_SERVICE. For these services this method will return null. Generally, if you are running as an instant app you should always check whether the result of this method is null.

Parameters
name String: The name of the desired service. Value is android.content.Context#POWER_SERVICE, android.content.Context#WINDOW_SERVICE, android.content.Context#LAYOUT_INFLATER_SERVICE, android.content.Context#ACCOUNT_SERVICE, android.content.Context#ACTIVITY_SERVICE, android.content.Context#ALARM_SERVICE, android.content.Context#NOTIFICATION_SERVICE, android.content.Context#ACCESSIBILITY_SERVICE, android.content.Context#CAPTIONING_SERVICE, android.content.Context#KEYGUARD_SERVICE, android.content.Context#LOCATION_SERVICE, android.content.Context#SEARCH_SERVICE, android.content.Context#SENSOR_SERVICE, android.content.Context.SENSOR_PRIVACY_SERVICE, android.content.Context#STORAGE_SERVICE, android.content.Context#STORAGE_STATS_SERVICE, android.content.Context#WALLPAPER_SERVICE, android.content.Context.TIME_ZONE_RULES_MANAGER_SERVICE, android.content.Context#VIBRATOR_SERVICE, android.content.Context#CONNECTIVITY_SERVICE, android.content.Context#IPSEC_SERVICE, android.content.Context#NETWORK_STATS_SERVICE, android.content.Context#WIFI_SERVICE, android.content.Context#WIFI_AWARE_SERVICE, android.content.Context#WIFI_P2P_SERVICE, android.content.Context.WIFI_SCANNING_SERVICE, android.content.Context#WIFI_RTT_RANGING_SERVICE, android.content.Context#NSD_SERVICE, android.content.Context#AUDIO_SERVICE, android.content.Context#FINGERPRINT_SERVICE, android.content.Context#BIOMETRIC_SERVICE, android.content.Context#MEDIA_ROUTER_SERVICE, android.content.Context#TELEPHONY_SERVICE, android.content.Context#TELEPHONY_SUBSCRIPTION_SERVICE, android.content.Context#CARRIER_CONFIG_SERVICE, android.content.Context#TELECOM_SERVICE, android.content.Context#CLIPBOARD_SERVICE, android.content.Context#INPUT_METHOD_SERVICE, android.content.Context#TEXT_SERVICES_MANAGER_SERVICE, android.content.Context#TEXT_CLASSIFICATION_SERVICE, android.content.Context#APPWIDGET_SERVICE, android.content.Context.ROLLBACK_SERVICE, android.content.Context#DROPBOX_SERVICE, android.content.Context#DEVICE_POLICY_SERVICE, android.content.Context#UI_MODE_SERVICE, android.content.Context#DOWNLOAD_SERVICE, android.content.Context#NFC_SERVICE, android.content.Context#BLUETOOTH_SERVICE, android.content.Context#USB_SERVICE, android.content.Context#LAUNCHER_APPS_SERVICE, android.content.Context#INPUT_SERVICE, android.content.Context#DISPLAY_SERVICE, android.content.Context#USER_SERVICE, android.content.Context#RESTRICTIONS_SERVICE, android.content.Context#APP_OPS_SERVICE, android.content.Context#ROLE_SERVICE, android.content.Context#CAMERA_SERVICE, android.content.Context#PRINT_SERVICE, android.content.Context#CONSUMER_IR_SERVICE, android.content.Context#TV_INPUT_SERVICE, android.content.Context#USAGE_STATS_SERVICE, android.content.Context#MEDIA_SESSION_SERVICE, android.content.Context#BATTERY_SERVICE, android.content.Context#JOB_SCHEDULER_SERVICE, android.content.Context#MEDIA_PROJECTION_SERVICE, android.content.Context#MIDI_SERVICE, android.content.Context.RADIO_SERVICE, android.content.Context#HARDWARE_PROPERTIES_SERVICE, android.content.Context#SHORTCUT_SERVICE, android.content.Context#SYSTEM_HEALTH_SERVICE, android.content.Context#COMPANION_DEVICE_SERVICE, android.content.Context#CROSS_PROFILE_APPS_SERVICE, or android.content.Context.PERMISSION_SERVICE This value must never be null.
Return
Any!: The service or null if the name does not exist.

See Also

getSystemService

added in API level 23
fun <T : Any!> getSystemService(serviceClass: Class<T>): T

Return the handle to a system-level service by class.

Currently available classes are: android.view.WindowManager, android.view.LayoutInflater, android.app.ActivityManager, android.os.PowerManager, android.app.AlarmManager, android.app.NotificationManager, android.app.KeyguardManager, android.location.LocationManager, android.app.SearchManager, android.os.Vibrator, android.net.ConnectivityManager, android.net.wifi.WifiManager, android.media.AudioManager, android.media.MediaRouter, android.telephony.TelephonyManager, android.telephony.SubscriptionManager, android.view.inputmethod.InputMethodManager, android.app.UiModeManager, android.app.DownloadManager, android.os.BatteryManager, android.app.job.JobScheduler, android.app.usage.NetworkStatsManager.

Note: System services obtained via this API may be closely associated with the Context in which they are obtained from. In general, do not share the service objects between various different contexts (Activities, Applications, Services, Providers, etc.)

Note: Instant apps, for which PackageManager#isInstantApp() returns true, don't have access to the following system services: DEVICE_POLICY_SERVICE, FINGERPRINT_SERVICE, KEYGUARD_SERVICE, SHORTCUT_SERVICE, USB_SERVICE, WALLPAPER_SERVICE, WIFI_P2P_SERVICE, WIFI_SERVICE, WIFI_AWARE_SERVICE. For these services this method will return null. Generally, if you are running as an instant app you should always check whether the result of this method is null.

Parameters
serviceClass Class<T>: The class of the desired service. This value must never be null.
Return
T: The service or null if the class is not a supported system service.

startForegroundService

added in API level 26
abstract fun startForegroundService(service: Intent!): ComponentName?

Similar to startService(android.content.Intent), but with an implicit promise that the Service will call startForeground(int, android.app.Notification) once it begins running. The service is given an amount of time comparable to the ANR interval to do this, otherwise the system will automatically stop the service and declare the app ANR.

Unlike the ordinary startService(android.content.Intent), this method can be used at any time, regardless of whether the app hosting the service is in a foreground state.

Parameters
service Intent!: Identifies the service to be started. The Intent must be fully explicit (supplying a component name). Additional values may be included in the Intent extras to supply arguments along with this specific start call.
Return
ComponentName?: If the service is being started or is already running, the ComponentName of the actual service that was started is returned; else if the service does not exist null is returned.
Exceptions
java.lang.SecurityException If the caller does not have permission to access the service or the service can not be found.

getDir

added in API level 1
abstract fun getDir(name: String!, mode: Int): File!

Retrieve, creating if needed, a new directory in which the application can place its own custom data files. You can use the returned File object to create and access files in this directory. Note that files created through a File object will only be accessible by your own application; you can only set the mode of the entire directory, not of individual files.

The returned path may change over time if the calling app is moved to an adopted storage device, so only relative paths should be persisted.

Apps require no extra permissions to read or write to the returned path, since this path lives in their private storage.

Parameters
name String!: Name of the directory to retrieve. This is a directory that is created as part of your application data.
mode String!: Operating mode. Value is either 0 or a combination of android.content.Context#MODE_PRIVATE, android.content.Context#MODE_WORLD_READABLE, android.content.Context#MODE_WORLD_WRITEABLE, and android.content.Context#MODE_APPEND
Return
File!: A File object for the requested directory. The directory will have been created if it does not already exist.

databaseList

added in API level 1
abstract fun databaseList(): Array<String!>!

Returns an array of strings naming the private databases associated with this Context's application package.

Return
Array<String!>!: Array of strings naming the private databases.

createPackageContext

added in API level 1
abstract fun createPackageContext(packageName: String!, flags: Int): Context!

Return a new Context object for the given application name. This Context is the same as what the named application gets when it is launched, containing the same resources and class loader. Each call to this method returns a new instance of a Context object; Context objects are not shared, however they share common state (Resources, ClassLoader, etc) so the Context instance itself is fairly lightweight.

Throws android.content.pm.PackageManager.NameNotFoundException if there is no application with the given package name.

Throws java.lang.SecurityException if the Context requested can not be loaded into the caller's process for security reasons (see CONTEXT_INCLUDE_CODE for more information}.

Parameters
packageName String!: Name of the application's package.
flags String!: Option flags. Value is either 0 or a combination of android.content.Context#CONTEXT_INCLUDE_CODE, android.content.Context#CONTEXT_IGNORE_SECURITY, android.content.Context#CONTEXT_RESTRICTED, android.content.Context.CONTEXT_DEVICE_PROTECTED_STORAGE, android.content.Context.CONTEXT_CREDENTIAL_PROTECTED_STORAGE, and android.content.Context.CONTEXT_REGISTER_PACKAGE
Return
Context!: A Context for the application.
Exceptions
java.lang.SecurityException  
android.content.pm.PackageManager.NameNotFoundException if there is no application with the given package name.

enforceUriPermission

added in API level 1
abstract fun enforceUriPermission(uri: Uri!, pid: Int, uid: Int, modeFlags: Int, message: String!): Unit

If a particular process and user ID has not been granted permission to access a specific URI, throw SecurityException. This only checks for permissions that have been explicitly granted -- if the given process/uid has more general access to the URI's content provider then this check will always fail.

Parameters
uri Uri!: The uri that is being checked.
pid Uri!: The process ID being checked against. Must be > 0.
uid Uri!: The user ID being checked against. A uid of 0 is the root user, which will pass every permission check.
modeFlags Uri!: The access modes to enforce. Value is either 0 or a combination of android.content.Intent#FLAG_GRANT_READ_URI_PERMISSION, and android.content.Intent#FLAG_GRANT_WRITE_URI_PERMISSION
message Uri!: A message to include in the exception if it is thrown.

enforceUriPermission

added in API level 1
abstract fun enforceUriPermission(uri: Uri?, readPermission: String?, writePermission: String?, pid: Int, uid: Int, modeFlags: Int, message: String?): Unit

Enforce both a Uri and normal permission. This allows you to perform both enforcePermission and enforceUriPermission in one call.

Parameters
uri Uri?: The Uri whose permission is to be checked, or null to not do this check. This value may be null.
readPermission Uri?: The permission that provides overall read access, or null to not do this check. This value may be null.
writePermission Uri?: The permission that provides overall write access, or null to not do this check. This value may be null.
pid Uri?: The process ID being checked against. Must be > 0.
uid Uri?: The user ID being checked against. A uid of 0 is the root user, which will pass every permission check.
modeFlags Uri?: The access modes to enforce. Value is either 0 or a combination of android.content.Intent#FLAG_GRANT_READ_URI_PERMISSION, and android.content.Intent#FLAG_GRANT_WRITE_URI_PERMISSION
message Uri?: A message to include in the exception if it is thrown. This value may be null.

removeStickyBroadcast

added in API level 1
abstract fun removeStickyBroadcast(intent: Intent!): Unit

Remove the data previously sent with sendStickyBroadcast, so that it is as if the sticky broadcast had never happened.
Requires android.Manifest.permission#BROADCAST_STICKY

Parameters
intent Intent!: The Intent that was previously broadcast.