MockContext
open class MockContext : Context
A mock android.content.Context
class. All methods are non-functional and throw java.lang.UnsupportedOperationException
. You can use this to inject other dependencies, mocks, or monitors into the classes you are testing.
Summary
Inherited constants |
From class Context
String |
ACCESSIBILITY_SERVICE
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.
|
String |
ACCOUNT_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.accounts.AccountManager for receiving intents at a time of your choosing.
|
String |
ACTIVITY_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.app.ActivityManager for interacting with the global system state.
|
String |
ALARM_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.app.AlarmManager for receiving intents at a time of your choosing.
|
String |
APPWIDGET_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.appwidget.AppWidgetManager for accessing AppWidgets.
|
String |
APP_OPS_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.app.AppOpsManager for tracking application operations on the device.
|
String |
APP_SEARCH_SERVICE
Use with getSystemService(java.lang.String) to retrieve an android.app.appsearch.AppSearchManager for indexing and querying app data managed by the system.
|
String |
AUDIO_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.media.AudioManager for handling management of volume, ringer modes and audio routing.
|
String |
BATTERY_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.os.BatteryManager for managing battery state.
|
Int |
BIND_ABOVE_CLIENT
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.
|
Int |
BIND_ADJUST_WITH_ACTIVITY
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.
|
Int |
BIND_ALLOW_ACTIVITY_STARTS
Flag for #bindService: If binding from an app that is visible, the bound service is allowed to start an activity from background. This was the default behavior before SDK version android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE . Since then, the default behavior changed to disallow the bound service to start a background activity even if the app bound to it is in foreground, unless this flag is specified when binding.
|
Int |
BIND_ALLOW_OOM_MANAGEMENT
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.
|
Int |
BIND_AUTO_CREATE
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.
|
Int |
BIND_DEBUG_UNBIND
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.
|
Int |
BIND_EXTERNAL_SERVICE
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.
This flag is NOT compatible with BindServiceFlags . If you need to use BindServiceFlags , you must use BIND_EXTERNAL_SERVICE_LONG instead.
|
Long |
BIND_EXTERNAL_SERVICE_LONG
Works in the same way as BIND_EXTERNAL_SERVICE , but it's defined as a long value that is compatible to BindServiceFlags .
|
Int |
BIND_IMPORTANT
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.
|
Int |
BIND_INCLUDE_CAPABILITIES
Flag for #bindService: If binding from an app that has specific capabilities due to its foreground state such as an activity or foreground service, then this flag will allow the bound app to get the same capabilities, as long as it has the required permissions as well. If binding from a top app and its target SDK version is at or above android.os.Build.VERSION_CODES#R , the app needs to explicitly use BIND_INCLUDE_CAPABILITIES flag to pass all capabilities to the service so the other app can have while-in-use access such as location, camera, microphone from background. If binding from a top app and its target SDK version is below android.os.Build.VERSION_CODES#R , BIND_INCLUDE_CAPABILITIES is implicit.
|
Int |
BIND_NOT_FOREGROUND
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.
|
Int |
BIND_NOT_PERCEPTIBLE
Flag for #bindService: If binding from an app that is visible or user-perceptible, lower the target service's importance to below the perceptible level. This allows the system to (temporarily) expunge the bound process from memory to make room for more important user-perceptible processes.
|
Int |
BIND_PACKAGE_ISOLATED_PROCESS
Flag for #bindIsolatedService: Bind the service into a shared isolated process, but only with other isolated services from the same package that declare the same process name.
Specifying this flag allows multiple isolated services defined in the same package to be running in a single shared isolated process. This shared isolated process must be specified since this flag will not work with the default application process.
This flag is different from BIND_SHARED_ISOLATED_PROCESS since it only allows binding services from the same package in the same shared isolated process. This also means the shared package isolated process is global, and not scoped to each potential calling app.
The shared isolated process instance is identified by the "android:process" attribute defined by the service. This flag cannot be used without this attribute set.
|
Int |
BIND_SHARED_ISOLATED_PROCESS
Flag for #bindIsolatedService: Bind the service into a shared isolated process. Specifying this flag allows multiple isolated services to be running in a single shared isolated process. The shared isolated process instance is identified by the instanceName parameter in bindIsolatedService(android.content.Intent,int,java.lang.String,java.util.concurrent.Executor,android.content.ServiceConnection) . Subsequent calls to #bindIsolatedService with the same instanceName will cause the isolated service to be co-located in the same shared isolated process. Note that the shared isolated process is scoped to the calling app; once created, only the calling app can bind additional isolated services into the shared process. However, the services themselves can come from different APKs and therefore different vendors. Only services that set the android.R.attr#allowSharedIsolatedProcess attribute to true are allowed to be bound into a shared isolated process.
|
Int |
BIND_WAIVE_PRIORITY
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.
|
String |
BIOMETRIC_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.hardware.biometrics.BiometricManager for handling biometric and PIN/pattern/password authentication.
|
String |
BLOB_STORE_SERVICE
Use with getSystemService(java.lang.String) to retrieve a for contributing and accessing data blobs from the blob store maintained by the system.
|
String |
BLUETOOTH_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.bluetooth.BluetoothManager for using Bluetooth.
|
String |
BUGREPORT_SERVICE
Service to capture a bugreport.
|
String |
CAMERA_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.hardware.camera2.CameraManager for interacting with camera devices.
|
String |
CAPTIONING_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.view.accessibility.CaptioningManager for obtaining captioning properties and listening for changes in captioning preferences.
|
String |
CARRIER_CONFIG_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.telephony.CarrierConfigManager for reading carrier configuration values.
|
String |
CLIPBOARD_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.content.ClipboardManager for accessing and modifying the contents of the global clipboard.
|
String |
COMPANION_DEVICE_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.companion.CompanionDeviceManager for managing companion devices
|
String |
CONNECTIVITY_DIAGNOSTICS_SERVICE
Use with getSystemService(java.lang.String) to retrieve a for performing network connectivity diagnostics as well as receiving network connectivity information from the system.
|
String |
CONNECTIVITY_SERVICE
Use with getSystemService(java.lang.String) to retrieve a for handling management of network connections.
|
String |
CONSUMER_IR_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.hardware.ConsumerIrManager for transmitting infrared signals from the device.
|
String |
CONTACT_KEYS_SERVICE
Use with getSystemService(java.lang.String) to retrieve a E2eeContactKeysManager to managing contact keys.
|
Int |
CONTEXT_IGNORE_SECURITY
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!
|
Int |
CONTEXT_INCLUDE_CODE
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.
|
Int |
CONTEXT_RESTRICTED
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.
|
String |
CREDENTIAL_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.credentials.CredentialManager to authenticate a user to your app.
|
String |
CROSS_PROFILE_APPS_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.content.pm.CrossProfileApps for cross profile operations.
|
Int |
DEVICE_ID_DEFAULT
The default device ID, which is the ID of the primary (non-virtual) device.
|
Int |
DEVICE_ID_INVALID
Invalid device ID.
|
String |
DEVICE_LOCK_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.devicelock.DeviceLockManager .
|
String |
DEVICE_POLICY_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.app.admin.DevicePolicyManager for working with global device policy management.
|
String |
DISPLAY_HASH_SERVICE
Use with getSystemService(java.lang.String) to access android.view.displayhash.DisplayHashManager to handle display hashes.
|
String |
DISPLAY_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.hardware.display.DisplayManager for interacting with display devices.
|
String |
DOMAIN_VERIFICATION_SERVICE
Use with getSystemService(java.lang.String) to access android.content.pm.verify.domain.DomainVerificationManager to retrieve approval and user state for declared web domains.
|
String |
DOWNLOAD_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.app.DownloadManager for requesting HTTP downloads.
|
String |
DROPBOX_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.os.DropBoxManager instance for recording diagnostic logs.
|
String |
EUICC_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.telephony.euicc.EuiccManager to manage the device eUICC (embedded SIM).
|
String |
FILE_INTEGRITY_SERVICE
Use with getSystemService(java.lang.String) to retrieve an android.security.FileIntegrityManager .
|
String |
FINGERPRINT_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.hardware.fingerprint.FingerprintManager for handling management of fingerprints.
|
String |
GAME_SERVICE
Use with getSystemService(java.lang.String) to retrieve a GameManager .
|
String |
GRAMMATICAL_INFLECTION_SERVICE
Use with getSystemService(java.lang.String) to retrieve a GrammaticalInflectionManager .
|
String |
HARDWARE_PROPERTIES_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.os.HardwarePropertiesManager for accessing the hardware properties service.
|
String |
HEALTHCONNECT_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.health.connect.HealthConnectManager .
|
String |
INPUT_METHOD_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.view.inputmethod.InputMethodManager for accessing input methods.
|
String |
INPUT_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.hardware.input.InputManager for interacting with input devices.
|
String |
IPSEC_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.net.IpSecManager for encrypting Sockets or Networks with IPSec.
|
String |
JOB_SCHEDULER_SERVICE
Use with getSystemService(java.lang.String) to retrieve a instance for managing occasional background tasks.
|
String |
KEYGUARD_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.app.KeyguardManager for controlling keyguard.
|
String |
LAUNCHER_APPS_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.content.pm.LauncherApps for querying and monitoring launchable apps across profiles of a user.
|
String |
LAYOUT_INFLATER_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.view.LayoutInflater for inflating layout resources in this context.
|
String |
LOCALE_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.app.LocaleManager .
|
String |
LOCATION_SERVICE
Use with getSystemService(java.lang.String) to retrieve a for controlling location updates.
|
String |
MEDIA_COMMUNICATION_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.media.MediaCommunicationManager for managing android.media.MediaSession2 .
|
String |
MEDIA_METRICS_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.media.metrics.MediaMetricsManager for interacting with media metrics on the device.
|
String |
MEDIA_PROJECTION_SERVICE
Use with getSystemService(java.lang.String) to retrieve a instance for managing media projection sessions.
|
String |
MEDIA_ROUTER_SERVICE
Use with #getSystemService to retrieve a android.media.MediaRouter for controlling and managing routing of media.
|
String |
MEDIA_SESSION_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.media.session.MediaSessionManager for managing media Sessions.
|
String |
MIDI_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.media.midi.MidiManager for accessing the MIDI service.
|
Int |
MODE_APPEND
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.
|
Int |
MODE_ENABLE_WRITE_AHEAD_LOGGING
Database open flag: when set, the database is opened with write-ahead logging enabled by default.
|
Int |
MODE_MULTI_PROCESS
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.
|
Int |
MODE_NO_LOCALIZED_COLLATORS
Database open flag: when set, the database is opened without support for localized collators.
|
Int |
MODE_PRIVATE
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).
|
Int |
MODE_WORLD_READABLE
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 .
|
Int |
MODE_WORLD_WRITEABLE
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 .
|
String |
NETWORK_STATS_SERVICE
Use with getSystemService(java.lang.String) to retrieve a for querying network usage stats.
|
String |
NFC_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.nfc.NfcManager for using NFC.
|
String |
NOTIFICATION_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.app.NotificationManager for informing the user of background events.
|
String |
NSD_SERVICE
Use with getSystemService(java.lang.String) to retrieve a for handling management of network service discovery
|
String |
OVERLAY_SERVICE
Use with getSystemService(java.lang.String) to retrieve a for managing overlay packages.
|
String |
PEOPLE_SERVICE
Use with getSystemService(java.lang.String) to access a PeopleManager to interact with your published conversations.
|
String |
PERFORMANCE_HINT_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.os.PerformanceHintManager for accessing the performance hinting service.
|
String |
PERSISTENT_DATA_BLOCK_SERVICE
Use with getSystemService(java.lang.String) to retrieve a instance for interacting with a storage device that lives across factory resets.
|
String |
POWER_SERVICE
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.
|
String |
PRINT_SERVICE
android.print.PrintManager for printing and managing printers and print tasks.
|
String |
PROFILING_SERVICE
Use with getSystemService(java.lang.String) to retrieve an android.os.ProfilingManager .
|
Int |
RECEIVER_EXPORTED
Flag for #registerReceiver: The receiver can receive broadcasts from other Apps. Has the same behavior as marking a statically registered receiver with "exported=true"
|
Int |
RECEIVER_NOT_EXPORTED
Flag for #registerReceiver: The receiver cannot receive broadcasts from other Apps. Has the same behavior as marking a statically registered receiver with "exported=false"
|
Int |
RECEIVER_VISIBLE_TO_INSTANT_APPS
Flag for #registerReceiver: The receiver can receive broadcasts from Instant Apps.
|
String |
RESTRICTIONS_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.content.RestrictionsManager for retrieving application restrictions and requesting permissions for restricted operations.
|
String |
ROLE_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.app.role.RoleManager for managing roles.
|
String |
SEARCH_SERVICE
Use with getSystemService(java.lang.String) to retrieve a for handling searches.
Configuration#UI_MODE_TYPE_WATCH does not support android.app.SearchManager .
|
String |
SECURITY_STATE_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.os.SecurityStateManager for accessing the security state manager service.
|
String |
SENSOR_SERVICE
Use with getSystemService(java.lang.String) to retrieve a for accessing sensors.
|
String |
SHORTCUT_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.content.pm.ShortcutManager for accessing the launcher shortcut service.
|
String |
STATUS_BAR_SERVICE
Use with getSystemService(java.lang.String) to retrieve a for interacting with the status bar and quick settings.
|
String |
STORAGE_SERVICE
Use with getSystemService(java.lang.String) to retrieve a for accessing system storage functions.
|
String |
STORAGE_STATS_SERVICE
Use with getSystemService(java.lang.String) to retrieve a for accessing system storage statistics.
|
String |
SYSTEM_HEALTH_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.os.health.SystemHealthManager for accessing system health (battery, power, memory, etc) metrics.
|
String |
TELECOM_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.telecom.TelecomManager to manage telecom-related features of the device.
|
String |
TELEPHONY_IMS_SERVICE
Use with getSystemService(java.lang.String) to retrieve an android.telephony.ims.ImsManager .
|
String |
TELEPHONY_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.telephony.TelephonyManager for handling management the telephony features of the device.
|
String |
TELEPHONY_SUBSCRIPTION_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.telephony.SubscriptionManager for handling management the telephony subscriptions of the device.
|
String |
TEXT_CLASSIFICATION_SERVICE
Use with getSystemService(java.lang.String) to retrieve a TextClassificationManager for text classification services.
|
String |
TEXT_SERVICES_MANAGER_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.view.textservice.TextServicesManager for accessing text services.
|
String |
TV_INPUT_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.media.tv.TvInputManager for interacting with TV inputs on the device.
|
String |
TV_INTERACTIVE_APP_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.media.tv.interactive.TvInteractiveAppManager for interacting with TV interactive applications on the device.
|
String |
UI_MODE_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.app.UiModeManager for controlling UI modes.
|
String |
USAGE_STATS_SERVICE
Use with getSystemService(java.lang.String) to retrieve a for querying device usage stats.
|
String |
USB_SERVICE
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.
|
String |
USER_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.os.UserManager for managing users on devices that support multiple users.
|
String |
VIBRATOR_MANAGER_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.os.VibratorManager for accessing the device vibrators, interacting with individual ones and playing synchronized effects on multiple vibrators.
|
String |
VIBRATOR_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.os.Vibrator for interacting with the vibration hardware.
|
String |
VIRTUAL_DEVICE_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.companion.virtual.VirtualDeviceManager for managing virtual devices. On devices without PackageManager#FEATURE_COMPANION_DEVICE_SETUP system feature the getSystemService(java.lang.String) will return null .
|
String |
VPN_MANAGEMENT_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.net.VpnManager to manage profiles for the platform built-in VPN.
|
String |
WALLPAPER_SERVICE
Use with getSystemService(java.lang.String) to retrieve a com.android.server.WallpaperService for accessing wallpapers.
|
String |
WIFI_AWARE_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.net.wifi.aware.WifiAwareManager for handling management of Wi-Fi Aware.
|
String |
WIFI_P2P_SERVICE
Use with getSystemService(java.lang.String) to retrieve a for handling management of Wi-Fi peer-to-peer connections.
|
String |
WIFI_RTT_RANGING_SERVICE
Use with getSystemService(java.lang.String) to retrieve a for ranging devices with wifi.
|
String |
WIFI_SERVICE
Use with getSystemService(java.lang.String) to retrieve a for handling management of Wi-Fi access.
|
String |
WINDOW_SERVICE
Use with getSystemService(java.lang.String) to retrieve a android.view.WindowManager for accessing the system's window manager.
|
|
Inherited functions |
From class Context
Boolean |
bindIsolatedService(service: Intent, flags: Context.BindServiceFlags, instanceName: String, executor: Executor, conn: ServiceConnection)
See bindIsolatedService(android.content.Intent,int,java.lang.String,java.util.concurrent.Executor,android.content.ServiceConnection) Call BindServiceFlags#of(long) to obtain a BindServiceFlags object.
|
Boolean |
bindService(service: Intent, conn: ServiceConnection, flags: Context.BindServiceFlags)
See bindService(android.content.Intent,android.content.ServiceConnection,int) Call BindServiceFlags#of(long) to obtain a BindServiceFlags object.
|
Boolean |
bindService(service: Intent, flags: Context.BindServiceFlags, executor: Executor, conn: ServiceConnection)
See bindService(android.content.Intent,int,java.util.concurrent.Executor,android.content.ServiceConnection) Call BindServiceFlags#of(long) to obtain a BindServiceFlags object.
|
Boolean |
bindServiceAsUser(service: Intent, conn: ServiceConnection, flags: Context.BindServiceFlags, user: UserHandle)
See bindServiceAsUser(android.content.Intent,android.content.ServiceConnection,int,android.os.UserHandle) Call BindServiceFlags#of(long) to obtain a BindServiceFlags object.
|
IntArray |
checkCallingOrSelfUriPermissions(uris: MutableList<Uri!>, modeFlags: Int)
Determine whether the calling process of an IPC or you has been granted permission to access a list of URIs. This is the same as checkCallingUriPermission , except it grants your own permissions if you are not currently processing an IPC. Use with care!
|
IntArray |
checkCallingUriPermissions(uris: MutableList<Uri!>, modeFlags: Int)
Determine whether the calling process and uid has been granted permission to access a list of URIs. This is basically the same as calling checkUriPermissions(java.util.List,int,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.
|
Int |
checkContentUriPermissionFull(uri: Uri, pid: Int, uid: Int, modeFlags: Int)
Determine whether a particular process and uid has been granted permission to access a specific content URI.
Unlike checkUriPermission(android.net.Uri,int,int,int) , this method checks for general access to the URI's content provider, as well as explicitly granted permissions.
Note, this check will throw an IllegalArgumentException for non-content URIs.
|
IntArray |
checkUriPermissions(uris: MutableList<Uri!>, pid: Int, uid: Int, modeFlags: Int)
Determine whether a particular process and uid has been granted permission to access a list of URIs. 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. Note: On SDK Version android.os.Build.VERSION_CODES#S , calling this method from a secondary-user's context will incorrectly return PackageManager#PERMISSION_DENIED for all {code uris}.
|
Context |
createAttributionContext(attributionTag: String?)
Return a new Context object for the current Context but attribute to a different tag. In complex apps attribution tagging can be used to distinguish between separate logical parts.
|
Context |
createContext(contextParams: ContextParams)
Creates a context with specific properties and behaviors.
|
AttributionSource |
getAttributionSource()
|
String? |
getAttributionTag()
Attribution can be used in complex apps to logically separate parts of the app. E.g. a blogging app might also have a instant messaging app built in. In this case two separate tags can for used each sub-feature.
|
Int |
getColor(id: Int)
Returns a color associated with a particular resource ID and styled for the current theme.
|
ColorStateList |
getColorStateList(id: Int)
Returns a color state list associated with a particular resource ID and styled for the current theme.
|
Drawable? |
getDrawable(id: Int)
Returns a drawable object associated with a particular resource ID and styled for the current theme.
|
ContextParams? |
getParams()
Return the set of parameters which this Context was created with, if it was created via createContext(android.content.ContextParams) .
|
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.
|
T |
getSystemService(serviceClass: Class<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 , android.content.pm.verify.domain.DomainVerificationManager , android.view.displayhash.DisplayHashManager .
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 .
|
CharSequence |
getText(resId: Int)
Return a localized, styled CharSequence from the application's package's default string table.
|
TypedArray |
obtainStyledAttributes(attrs: IntArray)
Retrieve styled attribute information in this Context's theme. See android.content.res.Resources.Theme#obtainStyledAttributes(int[]) for more information.
|
TypedArray |
obtainStyledAttributes(resid: Int, attrs: IntArray)
Retrieve styled attribute information in this Context's theme. See android.content.res.Resources.Theme#obtainStyledAttributes(int, int[]) for more information.
|
TypedArray |
obtainStyledAttributes(set: AttributeSet?, attrs: IntArray)
Retrieve styled attribute information in this Context's theme. See android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int) for more information.
|
TypedArray |
obtainStyledAttributes(set: AttributeSet?, attrs: IntArray, defStyleAttr: Int, defStyleRes: Int)
Retrieve styled attribute information in this Context's theme. See android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int) for more information.
|
Unit |
registerComponentCallbacks(callback: ComponentCallbacks!)
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.
After Build.VERSION_CODES#S , registering the ComponentCallbacks to Context created via createWindowContext(int,android.os.Bundle) or createWindowContext(android.view.Display,int,android.os.Bundle) will receive ComponentCallbacks#onConfigurationChanged(Configuration) from Window Context rather than its base application. It is helpful if you want to handle UI components that associated with the Window Context when the Window Context has configuration changes.
After Build.VERSION_CODES#TIRAMISU , registering the ComponentCallbacks to Activity context will receive ComponentCallbacks#onConfigurationChanged(Configuration) from Activity#onConfigurationChanged(Configuration) rather than its base application.
After Build.VERSION_CODES#UPSIDE_DOWN_CAKE , registering the ComponentCallbacks to android.inputmethodservice.InputMethodService will receive ComponentCallbacks#onConfigurationChanged(Configuration) from InputmethodService rather than its base application. It is helpful if you want to handle UI components when the IME has configuration changes.
|
Unit |
registerDeviceIdChangeListener(executor: Executor, listener: IntConsumer)
Adds a new device ID changed listener to the Context , which will be called when the device association is changed by the system.
The callback can be called when an app is moved to a different device and the Context is not explicitly associated with a specific device.
When an application receives a device id update callback, this Context is guaranteed to also have an updated display ID(if any) and Configuration .
|
Unit |
revokeSelfPermissionOnKill(permName: String)
Triggers the asynchronous revocation of a runtime permission. If the permission is not currently granted, nothing happens (even if later granted by the user).
|
Unit |
revokeSelfPermissionsOnKill(permissions: MutableCollection<String!>)
Triggers the revocation of one or more permissions for the calling package. A package is only able to revoke runtime permissions. If a permission is not currently granted, it is ignored and will not get revoked (even if later granted by the user). Ultimately, you should never make assumptions about a permission status as users may grant or revoke them at any time.
Background permissions which have no corresponding foreground permission still granted once the revocation is effective will also be revoked.
The revocation happens asynchronously and kills all processes running in the calling UID. It will be triggered once it is safe to do so. In particular, it will not be triggered as long as the package remains in the foreground, or has any active manifest components (e.g. when another app is accessing a content provider in the package).
If you want to revoke the permissions right away, you could call System.exit() in Handler.postDelayed with a delay to allow completion of async IPC, But System.exit() could affect other apps that are accessing your app at the moment. For example, apps accessing a content provider in your app will all crash.
Note that the settings UI shows a permission group as granted as long as at least one permission in the group is granted. If you want the user to observe the revocation in the settings, you should revoke every permission in the target group. To learn the current list of permissions in a group, you may use PackageManager#getGroupOfPlatformPermission(String, Executor, Consumer) and PackageManager#getPlatformPermissionsForGroup(String, Executor, Consumer) . This list of permissions may evolve over time, so it is recommended to check whether it contains any permission you wish to retain before trying to revoke an entire group.
|
Unit |
sendBroadcastWithMultiplePermissions(intent: Intent, receiverPermissions: Array<String!>)
Broadcast the given intent to all interested BroadcastReceivers, allowing an array of required permissions 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.
|
Unit |
sendOrderedBroadcast(intent: Intent, receiverPermission: String?, options: Bundle?)
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.
|
Unit |
unregisterComponentCallbacks(callback: ComponentCallbacks!)
Remove a ComponentCallbacks object that was previously registered with registerComponentCallbacks(android.content.ComponentCallbacks) .
|
Unit |
unregisterDeviceIdChangeListener(listener: IntConsumer)
Removes a device ID changed listener from the Context. It's a no-op if the listener is not already registered.
|
|
Public constructors
MockContext
MockContext()
Public methods
bindIsolatedService
open fun bindIsolatedService(
service: Intent,
flags: Int,
instanceName: String,
executor: Executor,
conn: ServiceConnection
): Boolean
Parameters |
service |
Intent: Identifies the service to connect to. The Intent must specify an explicit component name. This value cannot be null . |
flags |
Int: Operation options for the binding as per #bindService. |
instanceName |
String: Unique identifier for the service instance. Each unique name here will result in a different service instance being created. Identifiers must only contain ASCII letters, digits, underscores, and periods. This value cannot be null . |
executor |
Executor: Callbacks on ServiceConnection will be called on executor. Must use same instance for the same instance of ServiceConnection. This value cannot be null . Callback and listener events are dispatched through this Executor , providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor() . Otherwise, provide an Executor that dispatches to an appropriate thread. |
conn |
ServiceConnection: Receives information as the service is started and stopped. This must be a valid ServiceConnection object; it must not 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 |
java.lang.IllegalArgumentException |
If the instanceName is invalid. |
bindService
open fun bindService(
service: Intent,
conn: ServiceConnection,
flags: Int
): Boolean
Parameters |
service |
Intent: Identifies the service to connect to. The Intent must specify an explicit component name. This value cannot be null . |
conn |
ServiceConnection: Receives information as the service is started and stopped. This must be a valid ServiceConnection object; it must not be null. |
flags |
Int: Operation options for the binding. Can be:
|
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. Regardless of the return value, 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 cannot be found. Call unbindService to release the connection when this exception is thrown. |
bindService
open fun bindService(
service: Intent,
flags: Int,
executor: Executor,
conn: ServiceConnection
): Boolean
Parameters |
executor |
Executor: Callbacks on ServiceConnection will be called on executor. Must use same instance for the same instance of ServiceConnection. This value cannot be null . Callback and listener events are dispatched through this Executor , providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor() . Otherwise, provide an Executor that dispatches to an appropriate thread. |
service |
Intent: This value cannot be null . |
flags |
Int: 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 , android.content.Context#BIND_ADJUST_WITH_ACTIVITY , android.content.Context#BIND_NOT_PERCEPTIBLE , android.content.Context#BIND_ALLOW_ACTIVITY_STARTS , android.content.Context#BIND_INCLUDE_CAPABILITIES , android.content.Context#BIND_SHARED_ISOLATED_PROCESS , android.content.Context#BIND_PACKAGE_ISOLATED_PROCESS , and android.content.Context#BIND_EXTERNAL_SERVICE |
conn |
ServiceConnection: This value cannot be null . |
checkCallingOrSelfPermission
open fun checkCallingOrSelfPermission(permission: String): Int
Parameters |
permission |
String: The name of the permission being checked. This value cannot be null . |
checkCallingOrSelfUriPermission
open fun checkCallingOrSelfUriPermission(
uri: Uri!,
modeFlags: Int
): Int
checkCallingPermission
open fun checkCallingPermission(permission: String): Int
Parameters |
permission |
String: The name of the permission being checked. This value cannot be null . |
checkCallingUriPermission
open fun checkCallingUriPermission(
uri: Uri!,
modeFlags: Int
): Int
checkPermission
open fun checkPermission(
permission: String,
pid: Int,
uid: Int
): Int
Parameters |
permission |
String: The name of the permission being checked. This value cannot be null . |
pid |
Int: The process ID being checked against. Must be > 0. |
uid |
Int: The UID being checked against. A uid of 0 is the root user, which will pass every permission check. |
checkSelfPermission
open fun checkSelfPermission(permission: String): Int
Parameters |
permission |
String: The name of the permission being checked. This value cannot be null . |
checkUriPermission
open fun checkUriPermission(
uri: Uri!,
pid: Int,
uid: Int,
modeFlags: Int
): Int
checkUriPermission
open fun checkUriPermission(
uri: Uri?,
readPermission: String?,
writePermission: String?,
pid: Int,
uid: Int,
modeFlags: Int
): Int
Parameters |
uri |
Uri?: The Uri whose permission is to be checked, or null to not do this check. |
readPermission |
String?: The permission that provides overall read access, or null to not do this check. |
writePermission |
String?: The permission that provides overall write access, or null to not do this check. |
pid |
Int: The process ID being checked against. Must be > 0. |
uid |
Int: The UID being checked against. A uid of 0 is the root user, which will pass every permission check. |
modeFlags |
Int: 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 |
clearWallpaper
open fun clearWallpaper(): Unit
createConfigurationContext
open fun createConfigurationContext(overrideConfiguration: Configuration): Context!
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 cannot be null . |
createDeviceContext
open fun createDeviceContext(deviceId: Int): Context
Returns a new Context
object from the current context but with device association given by the deviceId
. Each call to this method returns a new instance of a context object. Context objects are not shared; however, common state (such as the ClassLoader
and other resources for the same configuration) can be shared, so the Context
itself is lightweight.
Applications that run on virtual devices may use this method to access the default device capabilities and functionality (by passing Context#DEVICE_ID_DEFAULT
. Similarly, applications running on the default device may access the functionality of virtual devices.
Note that the newly created instance will be associated with the same display as the parent Context, regardless of the device ID passed here.
Parameters |
deviceId |
Int: The ID of the device to associate with this context. |
Return |
Context |
This value cannot be null . |
Exceptions |
java.lang.IllegalArgumentException |
if the given device ID is not a valid ID of the default device or a virtual device. |
createDeviceProtectedStorageContext
open fun createDeviceProtectedStorageContext(): Context!
createDisplayContext
open fun createDisplayContext(display: Display): Context!
Parameters |
display |
Display: The display to which the current context's resources are adjusted. This value cannot be null . |
Return |
Context! |
A context for the display. |
createPackageContext
open fun createPackageContext(
packageName: String!,
flags: Int
): Context!
Exceptions |
java.lang.SecurityException |
|
android.content.pm.PackageManager.NameNotFoundException |
if there is no application with the given package name. |
createWindowContext
open fun createWindowContext(
type: Int,
options: Bundle?
): Context
Creates a Context for a non-activity window.
A window context is a context that can be used to add non-activity windows, such as android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY
. A window context must be created from a context that has an associated Display
, such as Activity
or a context created with createDisplayContext(android.view.Display)
.
The window context is created with the appropriate Configuration
for the area of the display that the windows created with it can occupy; it must be used when inflating
views, such that they can be inflated with proper Resources
. Below is a sample code to add an application overlay window on the primary display:
...
final DisplayManager dm = anyContext.getSystemService(DisplayManager.class);
final Display primaryDisplay = dm.getDisplay(DEFAULT_DISPLAY);
final Context windowContext = anyContext.createDisplayContext(primaryDisplay)
.createWindowContext(TYPE_APPLICATION_OVERLAY, null);
final View overlayView = Inflater.from(windowContext).inflate(someLayoutXml, null);
// WindowManager.LayoutParams initialization
...
// The types used in addView and createWindowContext must match.
mParams.type = TYPE_APPLICATION_OVERLAY;
...
windowContext.getSystemService(WindowManager.class).addView(overlayView, mParams);
This context's configuration and resources are adjusted to an area of the display where the windows with provided type will be added. Note that all windows associated with the same context will have an affinity and can only be moved together between different displays or areas on a display. If there is a need to add different window types, or non-associated windows, separate Contexts should be used.
Creating a window context is an expensive operation. Misuse of this API may lead to a huge performance drop. The best practice is to use the same window context when possible. An approach is to create one window context with specific window type and display and use it everywhere it's needed.
After Build.VERSION_CODES#S
, window context provides the capability to receive configuration changes for existing token by overriding the token
of the android.view.WindowManager.LayoutParams
passed in WindowManager#addView(View, LayoutParams)
. This is useful when an application needs to attach its window to an existing activity for window token sharing use-case.
Note that the window context in Build.VERSION_CODES#R
didn't have this capability. This is a no-op for the window context in Build.VERSION_CODES#R
.
Below is sample code to
attach an existing token to a window context:
final DisplayManager dm = anyContext.getSystemService(DisplayManager.class);
final Display primaryDisplay = dm.getDisplay(DEFAULT_DISPLAY);
final Context windowContext = anyContext.createWindowContext(primaryDisplay,
TYPE_APPLICATION, null);
// Get an existing token.
final IBinder existingToken = activity.getWindow().getAttributes().token;
// The types used in addView() and createWindowContext() must match.
final WindowManager.LayoutParams params = new WindowManager.LayoutParams(TYPE_APPLICATION);
params.token = existingToken;
// After WindowManager#addView(), the server side will extract the provided token from
// LayoutParams#token (existingToken in the sample code), and switch to propagate
// configuration changes from the node associated with the provided token.
windowContext.getSystemService(WindowManager.class).addView(overlayView, mParams);
After Build.VERSION_CODES#S
, window context provides the capability to listen to its Configuration
changes by calling registerComponentCallbacks(android.content.ComponentCallbacks)
, while other kinds of Context
will register the ComponentCallbacks
to its
. Note that window context only propagate ComponentCallbacks#onConfigurationChanged(Configuration)
callback. ComponentCallbacks#onLowMemory()
or other callbacks in ComponentCallbacks2
won't be invoked.
Note that using android.app.Application
or android.app.Service
context for UI-related queries may result in layout or continuity issues on devices with variable screen sizes (e.g. foldables) or in multi-window modes, since these non-UI contexts may not reflect the Configuration
changes for the visual container.
Parameters |
type |
Int: Window type in WindowManager.LayoutParams Value is android.view.WindowManager.LayoutParams#TYPE_BASE_APPLICATION , android.view.WindowManager.LayoutParams#TYPE_APPLICATION , android.view.WindowManager.LayoutParams#TYPE_APPLICATION_STARTING , android.view.WindowManager.LayoutParams#TYPE_DRAWN_APPLICATION , android.view.WindowManager.LayoutParams#TYPE_APPLICATION_PANEL , android.view.WindowManager.LayoutParams#TYPE_APPLICATION_MEDIA , android.view.WindowManager.LayoutParams#TYPE_APPLICATION_SUB_PANEL , android.view.WindowManager.LayoutParams#TYPE_APPLICATION_ATTACHED_DIALOG , android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY, android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ABOVE_SUB_PANEL, android.view.WindowManager.LayoutParams#TYPE_STATUS_BAR , android.view.WindowManager.LayoutParams#TYPE_SEARCH_BAR , android.view.WindowManager.LayoutParams#TYPE_PHONE , android.view.WindowManager.LayoutParams#TYPE_SYSTEM_ALERT , android.view.WindowManager.LayoutParams.TYPE_KEYGUARD, android.view.WindowManager.LayoutParams#TYPE_TOAST , android.view.WindowManager.LayoutParams#TYPE_SYSTEM_OVERLAY , android.view.WindowManager.LayoutParams#TYPE_PRIORITY_PHONE , android.view.WindowManager.LayoutParams#TYPE_SYSTEM_DIALOG , android.view.WindowManager.LayoutParams#TYPE_KEYGUARD_DIALOG , android.view.WindowManager.LayoutParams#TYPE_SYSTEM_ERROR , android.view.WindowManager.LayoutParams#TYPE_INPUT_METHOD , android.view.WindowManager.LayoutParams#TYPE_INPUT_METHOD_DIALOG , android.view.WindowManager.LayoutParams#TYPE_WALLPAPER , android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL, android.view.WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY, android.view.WindowManager.LayoutParams.TYPE_DRAG, android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL, android.view.WindowManager.LayoutParams.TYPE_POINTER, android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR, android.view.WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY, android.view.WindowManager.LayoutParams.TYPE_BOOT_PROGRESS, android.view.WindowManager.LayoutParams.TYPE_INPUT_CONSUMER, android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL, android.view.WindowManager.LayoutParams.TYPE_DISPLAY_OVERLAY, android.view.WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY, android.view.WindowManager.LayoutParams#TYPE_PRIVATE_PRESENTATION , android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION, android.view.WindowManager.LayoutParams#TYPE_ACCESSIBILITY_OVERLAY , android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION_STARTING, android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER, android.view.WindowManager.LayoutParams.TYPE_QS_DIALOG, android.view.WindowManager.LayoutParams.TYPE_SCREENSHOT, android.view.WindowManager.LayoutParams.TYPE_PRESENTATION, android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY , android.view.WindowManager.LayoutParams.TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY, android.view.WindowManager.LayoutParams.TYPE_NOTIFICATION_SHADE, or android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_ADDITIONAL |
options |
Bundle?: A bundle used to pass window-related options This value may be null . |
Return |
Context |
This value cannot be null . |
Exceptions |
java.lang.UnsupportedOperationException |
if this Context does not attach to a display, such as Application or Service . |
createWindowContext
open fun createWindowContext(
display: Display,
type: Int,
options: Bundle?
): Context
Creates a Context
for a non-activity
window on the given Display
.
Similar to createWindowContext(int,android.os.Bundle)
, but the display
is passed in, instead of implicitly using the original Context's Display
.
Parameters |
display |
Display: The Display to associate with This value cannot be null . |
type |
Int: Window type in WindowManager.LayoutParams Value is android.view.WindowManager.LayoutParams#TYPE_BASE_APPLICATION , android.view.WindowManager.LayoutParams#TYPE_APPLICATION , android.view.WindowManager.LayoutParams#TYPE_APPLICATION_STARTING , android.view.WindowManager.LayoutParams#TYPE_DRAWN_APPLICATION , android.view.WindowManager.LayoutParams#TYPE_APPLICATION_PANEL , android.view.WindowManager.LayoutParams#TYPE_APPLICATION_MEDIA , android.view.WindowManager.LayoutParams#TYPE_APPLICATION_SUB_PANEL , android.view.WindowManager.LayoutParams#TYPE_APPLICATION_ATTACHED_DIALOG , android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY, android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ABOVE_SUB_PANEL, android.view.WindowManager.LayoutParams#TYPE_STATUS_BAR , android.view.WindowManager.LayoutParams#TYPE_SEARCH_BAR , android.view.WindowManager.LayoutParams#TYPE_PHONE , android.view.WindowManager.LayoutParams#TYPE_SYSTEM_ALERT , android.view.WindowManager.LayoutParams.TYPE_KEYGUARD, android.view.WindowManager.LayoutParams#TYPE_TOAST , android.view.WindowManager.LayoutParams#TYPE_SYSTEM_OVERLAY , android.view.WindowManager.LayoutParams#TYPE_PRIORITY_PHONE , android.view.WindowManager.LayoutParams#TYPE_SYSTEM_DIALOG , android.view.WindowManager.LayoutParams#TYPE_KEYGUARD_DIALOG , android.view.WindowManager.LayoutParams#TYPE_SYSTEM_ERROR , android.view.WindowManager.LayoutParams#TYPE_INPUT_METHOD , android.view.WindowManager.LayoutParams#TYPE_INPUT_METHOD_DIALOG , android.view.WindowManager.LayoutParams#TYPE_WALLPAPER , android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL, android.view.WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY, android.view.WindowManager.LayoutParams.TYPE_DRAG, android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL, android.view.WindowManager.LayoutParams.TYPE_POINTER, android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR, android.view.WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY, android.view.WindowManager.LayoutParams.TYPE_BOOT_PROGRESS, android.view.WindowManager.LayoutParams.TYPE_INPUT_CONSUMER, android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL, android.view.WindowManager.LayoutParams.TYPE_DISPLAY_OVERLAY, android.view.WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY, android.view.WindowManager.LayoutParams#TYPE_PRIVATE_PRESENTATION , android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION, android.view.WindowManager.LayoutParams#TYPE_ACCESSIBILITY_OVERLAY , android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION_STARTING, android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER, android.view.WindowManager.LayoutParams.TYPE_QS_DIALOG, android.view.WindowManager.LayoutParams.TYPE_SCREENSHOT, android.view.WindowManager.LayoutParams.TYPE_PRESENTATION, android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY , android.view.WindowManager.LayoutParams.TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY, android.view.WindowManager.LayoutParams.TYPE_NOTIFICATION_SHADE, or android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_ADDITIONAL |
options |
Bundle?: A bundle used to pass window-related options. This value may be null . |
Return |
Context |
This value cannot be null . |
Exceptions |
java.lang.IllegalArgumentException |
if the Display is null . |
databaseList
open fun databaseList(): Array<String!>!
Return |
Array<String!>! |
Array of strings naming the private databases. |
deleteDatabase
open fun deleteDatabase(name: String!): Boolean
Parameters |
name |
String!: The name (unique in the application package) of the database. |
Return |
Boolean |
true if the database was successfully deleted; else false . |
deleteFile
open fun deleteFile(name: String!): Boolean
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 . |
deleteSharedPreferences
open fun deleteSharedPreferences(name: String!): Boolean
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 . |
enforceCallingOrSelfPermission
open fun enforceCallingOrSelfPermission(
permission: String,
message: String?
): Unit
Parameters |
permission |
String: The name of the permission being checked. This value cannot be null . |
message |
String?: A message to include in the exception if it is thrown. This value may be null . |
enforceCallingOrSelfUriPermission
open fun enforceCallingOrSelfUriPermission(
uri: Uri!,
modeFlags: Int,
message: String!
): Unit
enforceCallingPermission
open fun enforceCallingPermission(
permission: String,
message: String?
): Unit
Parameters |
permission |
String: The name of the permission being checked. This value cannot be null . |
message |
String?: A message to include in the exception if it is thrown. This value may be null . |
enforceCallingUriPermission
open fun enforceCallingUriPermission(
uri: Uri!,
modeFlags: Int,
message: String!
): Unit
enforcePermission
open fun enforcePermission(
permission: String,
pid: Int,
uid: Int,
message: String?
): Unit
Parameters |
permission |
String: The name of the permission being checked. This value cannot be null . |
pid |
Int: The process ID being checked against. Must be > 0. |
uid |
Int: The UID 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 . |
enforceUriPermission
open fun enforceUriPermission(
uri: Uri!,
pid: Int,
uid: Int,
modeFlags: Int,
message: String!
): Unit
enforceUriPermission
open fun enforceUriPermission(
uri: Uri?,
readPermission: String?,
writePermission: String?,
pid: Int,
uid: Int,
modeFlags: Int,
message: String?
): Unit
Parameters |
uri |
Uri?: The Uri whose permission is to be checked, or null to not do this check. |
readPermission |
String?: The permission that provides overall read access, or null to not do this check. |
writePermission |
String?: The permission that provides overall write access, or null to not do this check. |
pid |
Int: The process ID being checked against. Must be > 0. |
uid |
Int: The UID being checked against. A uid of 0 is the root user, which will pass every permission check. |
modeFlags |
Int: 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 |
String?: A message to include in the exception if it is thrown. This value may be null . |
fileList
open fun fileList(): Array<String!>!
Return |
Array<String!>! |
Array of strings naming the private files. |
getApplicationContext
open fun getApplicationContext(): Context!
getAssets
open fun getAssets(): AssetManager!
Return |
AssetManager! |
an AssetManager instance for the application's package |
getCacheDir
open fun getCacheDir(): File!
Return |
File! |
The path of the directory holding application cache files. |
getCodeCacheDir
open fun getCodeCacheDir(): File!
Return |
File! |
The path of the directory holding application code cache files. |
getDataDir
open fun getDataDir(): File!
getDatabasePath
open fun getDatabasePath(name: String!): File!
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. |
getDeviceId
open fun getDeviceId(): Int
Return |
Int |
the ID of the device this context is associated with. |
getDir
open fun getDir(
name: String!,
mode: Int
): File!
Return |
File! |
A File object for the requested directory. The directory will have been created if it does not already exist. |
getDisplay
open fun getDisplay(): Display
Return |
Display |
Returns the Display object this context is associated with. This value cannot be null . |
Exceptions |
java.lang.UnsupportedOperationException |
if the method is called on an instance that is not associated with any display. |
getExternalCacheDir
open fun getExternalCacheDir(): File?
Return |
File? |
the absolute path to application-specific directory. May return null if shared storage is not currently available. |
getExternalCacheDirs
open fun getExternalCacheDirs(): Array<File!>!
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() . |
getExternalFilesDir
open fun getExternalFilesDir(type: String?): File?
Return |
File? |
the absolute path to application-specific directory. May return null if shared storage is not currently available. |
getExternalFilesDirs
open fun getExternalFilesDirs(type: String!): Array<File!>!
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) . |
getExternalMediaDirs
open fun getExternalMediaDirs(): Array<File!>!
Return |
Array<File!>! |
the absolute paths to application-specific directories. Some individual paths may be null if that shared storage is not currently available. |
getFileStreamPath
open fun getFileStreamPath(name: String!): File!
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. |
getFilesDir
open fun getFilesDir(): File!
Return |
File! |
The path of the directory holding application files. |
getMainExecutor
open fun getMainExecutor(): Executor!
getMainLooper
open fun getMainLooper(): Looper!
Return |
Looper! |
The main looper. |
getNoBackupFilesDir
open fun getNoBackupFilesDir(): File!
Return |
File! |
The path of the directory holding application files that will not be automatically backed up to remote storage. |
getObbDir
open fun getObbDir(): File!
Return |
File! |
the absolute path to application-specific directory. May return null if shared storage is not currently available. |
getObbDirs
open fun getObbDirs(): Array<File!>!
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() |
getPackageCodePath
open fun getPackageCodePath(): String!
Return |
String! |
String Path to the code and assets. |
getPackageName
open fun getPackageName(): String!
getPackageResourcePath
open fun getPackageResourcePath(): String!
Return |
String! |
String Path to the resources. |
getResources
open fun getResources(): Resources!
Return |
Resources! |
a Resources instance for the application's package |
getSystemService
open fun getSystemService(name: String): Any!
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#HEALTHCONNECT_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#VIBRATOR_MANAGER_SERVICE , android.content.Context#VIBRATOR_SERVICE , android.content.Context.THREAD_NETWORK_SERVICE, android.content.Context#CONNECTIVITY_SERVICE , android.content.Context.PAC_PROXY_SERVICE, android.content.Context.VCN_MANAGEMENT_SERVICE, android.content.Context#IPSEC_SERVICE , android.content.Context#VPN_MANAGEMENT_SERVICE , android.content.Context.TEST_NETWORK_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.AUDIO_DEVICE_VOLUME_SERVICE, android.content.Context.AUTH_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#EUICC_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.REBOOT_READINESS_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_INTERACTIVE_APP_SERVICE , android.content.Context#TV_INPUT_SERVICE , android.content.Context#USAGE_STATS_SERVICE , android.content.Context#MEDIA_SESSION_SERVICE , android.content.Context#MEDIA_COMMUNICATION_SERVICE , android.content.Context#BATTERY_SERVICE , android.content.Context#JOB_SCHEDULER_SERVICE , android.content.Context#PERSISTENT_DATA_BLOCK_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#VIRTUAL_DEVICE_SERVICE , android.content.Context#CROSS_PROFILE_APPS_SERVICE , android.content.Context.PERMISSION_SERVICE, android.content.Context.LIGHTS_SERVICE, android.content.Context#LOCALE_SERVICE , android.content.Context.UWB_SERVICE, android.content.Context#MEDIA_METRICS_SERVICE , android.content.Context#DISPLAY_HASH_SERVICE , android.content.Context#CREDENTIAL_SERVICE , android.content.Context#DEVICE_LOCK_SERVICE , android.content.Context.VIRTUALIZATION_SERVICE, android.content.Context#GRAMMATICAL_INFLECTION_SERVICE , android.content.Context#SECURITY_STATE_SERVICE , or android.content.Context#CONTACT_KEYS_SERVICE This value cannot be null . |
Return |
Any! |
The service or null if the name does not exist. |
getSystemServiceName
open fun getSystemServiceName(serviceClass: Class<*>): String?
Parameters |
serviceClass |
Class<*>: The class of the desired service. This value cannot be null . |
Return |
String? |
The service name or null if the class is not a supported system service. |
getWallpaper
open fun getWallpaper(): Drawable!
getWallpaperDesiredMinimumHeight
open fun getWallpaperDesiredMinimumHeight(): Int
getWallpaperDesiredMinimumWidth
open fun getWallpaperDesiredMinimumWidth(): Int
grantUriPermission
open fun grantUriPermission(
toPackage: String!,
uri: Uri!,
modeFlags: Int
): Unit
isDeviceProtectedStorage
open fun isDeviceProtectedStorage(): Boolean
isRestricted
open fun isRestricted(): Boolean
Return |
Boolean |
true if this Context is restricted, false otherwise. |
isUiContext
open fun isUiContext(): Boolean
{@hide}
moveDatabaseFrom
open fun moveDatabaseFrom(
sourceContext: Context!,
name: String!
): Boolean
Parameters |
sourceContext |
Context!: The source context which contains the existing database to move. |
name |
String!: 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 . |
moveSharedPreferencesFrom
open fun moveSharedPreferencesFrom(
sourceContext: Context!,
name: String!
): Boolean
Parameters |
sourceContext |
Context!: The source context which contains the existing shared preferences to move. |
name |
String!: 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 . |
open fun openFileInput(name: String!): FileInputStream!
Parameters |
name |
String!: The name of the file to open; can not contain path separators. |
peekWallpaper
open fun peekWallpaper(): Drawable!
registerReceiver
open fun registerReceiver(
receiver: BroadcastReceiver?,
filter: IntentFilter!
): Intent?
Parameters |
receiver |
BroadcastReceiver?: The BroadcastReceiver to handle the broadcast. This value may be null . |
filter |
IntentFilter!: Selects the Intent broadcasts to be received. |
Return |
Intent? |
The first sticky intent found that matches filter, or null if there are none. |
registerReceiver
open fun registerReceiver(
receiver: BroadcastReceiver!,
filter: IntentFilter!,
broadcastPermission: String?,
scheduler: Handler?
): Intent?
Parameters |
receiver |
BroadcastReceiver!: The BroadcastReceiver to handle the broadcast. |
filter |
IntentFilter!: Selects the Intent broadcasts to be received. |
broadcastPermission |
String?: String naming a permissions that a broadcaster must hold in order to send an Intent to you. If null, no permission is required. |
scheduler |
Handler?: Handler identifying the thread that will receive the Intent. If null, the main thread of the process will be used. |
Return |
Intent? |
The first sticky intent found that matches filter, or null if there are none. |
removeStickyBroadcast
open fun removeStickyBroadcast(intent: Intent!): Unit
Parameters |
intent |
Intent!: The Intent that was previously broadcast. |
removeStickyBroadcastAsUser
open fun removeStickyBroadcastAsUser(
intent: Intent!,
user: UserHandle!
): Unit
Parameters |
intent |
Intent!: The Intent that was previously broadcast. |
user |
UserHandle!: UserHandle to remove the sticky broadcast from. |
revokeUriPermission
open fun revokeUriPermission(
uri: Uri!,
modeFlags: Int
): Unit
revokeUriPermission
open fun revokeUriPermission(
targetPackage: String!,
uri: Uri!,
modeFlags: Int
): Unit
sendBroadcast
open fun sendBroadcast(intent: Intent!): Unit
Parameters |
intent |
Intent!: The Intent to broadcast; all receivers matching this Intent will receive the broadcast. |
sendBroadcast
open fun sendBroadcast(
intent: Intent!,
receiverPermission: String?
): Unit
Parameters |
intent |
Intent!: The Intent to broadcast; all receivers matching this Intent will receive the broadcast. |
receiverPermission |
String?: (optional) String naming a permission that a receiver must hold in order to receive your broadcast. If null, no permission is required. |
sendBroadcastAsUser
open fun sendBroadcastAsUser(
intent: Intent!,
user: UserHandle!
): Unit
Parameters |
intent |
Intent!: The intent to broadcast |
user |
UserHandle!: UserHandle to send the intent to. |
sendBroadcastAsUser
open fun sendBroadcastAsUser(
intent: Intent!,
user: UserHandle!,
receiverPermission: String?
): Unit
Parameters |
intent |
Intent!: The Intent to broadcast; all receivers matching this Intent will receive the broadcast. |
user |
UserHandle!: UserHandle to send the intent to. |
receiverPermission |
String?: (optional) String naming a permission that a receiver must hold in order to receive your broadcast. If null, no permission is required. |
sendOrderedBroadcast
open fun sendOrderedBroadcast(
intent: Intent!,
receiverPermission: String?
): Unit
Parameters |
intent |
Intent!: The Intent to broadcast; all receivers matching this Intent will receive the broadcast. |
receiverPermission |
String?: (optional) String naming a permissions that a receiver must hold in order to receive your broadcast. If null, no permission is required. |
sendOrderedBroadcast
open fun sendOrderedBroadcast(
intent: Intent,
receiverPermission: String?,
resultReceiver: BroadcastReceiver?,
scheduler: Handler?,
initialCode: Int,
initialData: String?,
initialExtras: Bundle?
): Unit
Parameters |
intent |
Intent: The Intent to broadcast; all receivers matching this Intent will receive the broadcast. This value cannot be null . |
receiverPermission |
String?: String naming a permissions that a receiver must hold in order to receive your broadcast. If null, no permission is required. |
resultReceiver |
BroadcastReceiver?: Your own BroadcastReceiver to treat as the final receiver of the broadcast. This value may be null . |
scheduler |
Handler?: A custom Handler with which to schedule the resultReceiver callback; if null it will be scheduled in the Context's main thread. |
initialCode |
Int: An initial value for the result code. Often Activity.RESULT_OK. |
initialData |
String?: An initial value for the result data. Often null. |
initialExtras |
Bundle?: An initial value for the result extras. Often null. |
sendOrderedBroadcast
open fun sendOrderedBroadcast(
intent: Intent,
receiverPermission: String?,
receiverAppOp: String?,
resultReceiver: BroadcastReceiver?,
scheduler: Handler?,
initialCode: Int,
initialData: String?,
initialExtras: Bundle?
): Unit
Parameters |
intent |
Intent: The Intent to broadcast; all receivers matching this Intent will receive the broadcast. This value cannot be null . |
receiverPermission |
String?: String naming a permissions that a receiver must hold in order to receive your broadcast. If null, no permission is required. |
receiverAppOp |
String?: The app op associated with the broadcast. If null, no appOp is required. If both receiverAppOp and receiverPermission are non-null, a receiver must have both of them to receive the broadcast |
resultReceiver |
BroadcastReceiver?: Your own BroadcastReceiver to treat as the final receiver of the broadcast. This value may be null . |
scheduler |
Handler?: A custom Handler with which to schedule the resultReceiver callback; if null it will be scheduled in the Context's main thread. |
initialCode |
Int: An initial value for the result code. Often Activity.RESULT_OK. |
initialData |
String?: An initial value for the result data. Often null. |
initialExtras |
Bundle?: An initial value for the result extras. Often null. |
sendOrderedBroadcastAsUser
open fun sendOrderedBroadcastAsUser(
intent: Intent!,
user: UserHandle!,
receiverPermission: String?,
resultReceiver: BroadcastReceiver!,
scheduler: Handler?,
initialCode: Int,
initialData: String?,
initialExtras: Bundle?
): Unit
Parameters |
intent |
Intent!: The Intent to broadcast; all receivers matching this Intent will receive the broadcast. |
user |
UserHandle!: UserHandle to send the intent to. |
receiverPermission |
String?: String naming a permissions that a receiver must hold in order to receive your broadcast. If null, no permission is required. |
resultReceiver |
BroadcastReceiver!: Your own BroadcastReceiver to treat as the final receiver of the broadcast. |
scheduler |
Handler?: A custom Handler with which to schedule the resultReceiver callback; if null it will be scheduled in the Context's main thread. |
initialCode |
Int: An initial value for the result code. Often Activity.RESULT_OK. |
initialData |
String?: An initial value for the result data. Often null. |
initialExtras |
Bundle?: An initial value for the result extras. Often null. |
sendStickyBroadcast
open fun sendStickyBroadcast(intent: Intent!): Unit
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. |
sendStickyBroadcast
open fun sendStickyBroadcast(
intent: Intent,
options: Bundle?
): Unit
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. This value cannot be null . |
options |
Bundle?: (optional) Additional sending options, generated from a android.app.BroadcastOptions . This value may be null . |
sendStickyBroadcastAsUser
open fun sendStickyBroadcastAsUser(
intent: Intent!,
user: UserHandle!
): Unit
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 |
UserHandle!: UserHandle to send the intent to. |
sendStickyOrderedBroadcast
open fun sendStickyOrderedBroadcast(
intent: Intent!,
resultReceiver: BroadcastReceiver!,
scheduler: Handler?,
initialCode: Int,
initialData: String?,
initialExtras: Bundle?
): Unit
Parameters |
intent |
Intent!: The Intent to broadcast; all receivers matching this Intent will receive the broadcast. |
resultReceiver |
BroadcastReceiver!: Your own BroadcastReceiver to treat as the final receiver of the broadcast. |
scheduler |
Handler?: A custom Handler with which to schedule the resultReceiver callback; if null it will be scheduled in the Context's main thread. |
initialCode |
Int: An initial value for the result code. Often Activity.RESULT_OK. |
initialData |
String?: An initial value for the result data. Often null. |
initialExtras |
Bundle?: An initial value for the result extras. Often null. |
sendStickyOrderedBroadcastAsUser
open fun sendStickyOrderedBroadcastAsUser(
intent: Intent!,
user: UserHandle!,
resultReceiver: BroadcastReceiver!,
scheduler: Handler?,
initialCode: Int,
initialData: String?,
initialExtras: Bundle?
): Unit
Parameters |
intent |
Intent!: The Intent to broadcast; all receivers matching this Intent will receive the broadcast. |
user |
UserHandle!: UserHandle to send the intent to. |
resultReceiver |
BroadcastReceiver!: Your own BroadcastReceiver to treat as the final receiver of the broadcast. |
scheduler |
Handler?: A custom Handler with which to schedule the resultReceiver callback; if null it will be scheduled in the Context's main thread. |
initialCode |
Int: An initial value for the result code. Often Activity.RESULT_OK. |
initialData |
String?: An initial value for the result data. Often null. |
initialExtras |
Bundle?: An initial value for the result extras. Often null. |
setTheme
open fun setTheme(resid: Int): Unit
Parameters |
resid |
Int: The style resource describing the theme. |
setWallpaper
open fun setWallpaper(bitmap: Bitmap!): Unit
startActivities
open fun startActivities(intents: Array<Intent!>!): Unit
Parameters |
intents |
Array<Intent!>!: An array of Intents to be started. |
Exceptions |
android.content.ActivityNotFoundException |
|
startActivities
open fun startActivities(
intents: Array<Intent!>!,
options: Bundle!
): Unit
Exceptions |
android.content.ActivityNotFoundException |
|
startActivity
open fun startActivity(intent: Intent!): Unit
Parameters |
intent |
Intent!: The description of the activity to start. |
Exceptions |
android.content.ActivityNotFoundException |
` |
startActivity
open fun startActivity(
intent: Intent!,
options: Bundle?
): Unit
Parameters |
intent |
Intent!: The description of the activity to start. |
options |
Bundle?: 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. |
Exceptions |
android.content.ActivityNotFoundException |
|
startForegroundService
open fun startForegroundService(service: Intent!): ComponentName?
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. |
android.app.ForegroundServiceStartNotAllowedException |
If the caller app's targeting API is android.os.Build.VERSION_CODES#S or later, and the foreground service is restricted from start due to background restriction. |
startInstrumentation
open fun startInstrumentation(
className: ComponentName,
profileFile: String?,
arguments: Bundle?
): Boolean
Parameters |
className |
ComponentName: Name of the Instrumentation component to be run. This value cannot be null . |
profileFile |
String?: Optional path to write profiling data as the instrumentation runs, or null for no profiling. |
arguments |
Bundle?: Additional optional arguments to pass to the instrumentation, or null. |
Return |
Boolean |
true if the instrumentation was successfully started, else false if it could not be found. |
startIntentSender
open fun startIntentSender(
intent: IntentSender!,
fillInIntent: Intent?,
flagsMask: Int,
flagsValues: Int,
extraFlags: Int
): Unit
Parameters |
intent |
IntentSender!: The IntentSender to launch. |
fillInIntent |
Intent?: If non-null, this will be provided as the intent parameter to android.content.IntentSender#sendIntent. |
flagsMask |
Int: 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 , android.content.Intent.FLAG_RECEIVER_OFFLOAD, and android.content.Intent.FLAG_RECEIVER_OFFLOAD_FOREGROUND |
flagsValues |
Int: 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 , android.content.Intent.FLAG_RECEIVER_OFFLOAD, and android.content.Intent.FLAG_RECEIVER_OFFLOAD_FOREGROUND |
extraFlags |
Int: Always set to 0. |
startIntentSender
open fun startIntentSender(
intent: IntentSender!,
fillInIntent: Intent?,
flagsMask: Int,
flagsValues: Int,
extraFlags: Int,
options: Bundle?
): Unit
Parameters |
intent |
IntentSender!: The IntentSender to launch. |
fillInIntent |
Intent?: If non-null, this will be provided as the intent parameter to android.content.IntentSender#sendIntent. |
flagsMask |
Int: 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 , android.content.Intent.FLAG_RECEIVER_OFFLOAD, and android.content.Intent.FLAG_RECEIVER_OFFLOAD_FOREGROUND |
flagsValues |
Int: 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 , android.content.Intent.FLAG_RECEIVER_OFFLOAD, and android.content.Intent.FLAG_RECEIVER_OFFLOAD_FOREGROUND |
extraFlags |
Int: Always set to 0. |
options |
Bundle?: 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 . |
startService
open fun startService(service: Intent!): ComponentName?
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 |
Before Android android.os.Build.VERSION_CODES#S , 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), IllegalStateException was thrown. |
android.app.BackgroundServiceStartNotAllowedException |
On Android android.os.Build.VERSION_CODES#S and later, 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), android.app.BackgroundServiceStartNotAllowedException is thrown. This exception extends IllegalStateException , so apps can use catch (IllegalStateException) to catch both. |
stopService
open fun stopService(service: Intent!): Boolean
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). |
unbindService
open fun unbindService(conn: ServiceConnection): Unit
Parameters |
conn |
ServiceConnection: The connection interface previously supplied to bindService(). This parameter must not be null. |
unregisterReceiver
open fun unregisterReceiver(receiver: BroadcastReceiver!): Unit
Exceptions |
java.lang.IllegalArgumentException |
if the receiver was not previously registered or already unregistered. |
updateServiceGroup
open fun updateServiceGroup(
conn: ServiceConnection,
group: Int,
importance: Int
): Unit
Parameters |
conn |
ServiceConnection: The connection interface previously supplied to bindService(). This parameter must not be null. |
group |
Int: 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 |
Int: Additional importance of the processes within a group. Upon calling here, this will override any previous importance that was set for that process. The most important process is 0, and higher values are successively less important. You can view this as describing how to order the processes in an array, with the processes at the end of the array being the least important. This value has no meaning besides indicating how processes should be ordered in that array one after the other. This provides a way to fine-tune the system's process killing, guiding it to kill processes at the end of the array first. |