Context

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

Summary

Constants
String ACCESSIBILITY_SERVICE Use with getSystemService(String) to retrieve a AccessibilityManager for giving the user feedback for UI events through the registered event listeners.
String ACCOUNT_SERVICE Use with getSystemService(String) to retrieve a AccountManager for receiving intents at a time of your choosing.
String ACTIVITY_SERVICE Use with getSystemService(String) to retrieve a ActivityManager for interacting with the global system state.
String ALARM_SERVICE Use with getSystemService(String) to retrieve a AlarmManager for receiving intents at a time of your choosing.
String APP_OPS_SERVICE Use with getSystemService(String) to retrieve a AppOpsManager for tracking application operations on the device.
String AUDIO_SERVICE Use with getSystemService(String) to retrieve a AudioManager for handling management of volume, ringer modes and audio routing.
int BIND_ABOVE_CLIENT Flag for bindService(Intent, ServiceConnection, int) : indicates that the client application binding to this service considers the service to be more important than the app itself.
int BIND_ADJUST_WITH_ACTIVITY Flag for bindService(Intent, ServiceConnection, int) : 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_OOM_MANAGEMENT Flag for bindService(Intent, ServiceConnection, int) : allow the process hosting the bound service to go through its normal memory management.
int BIND_AUTO_CREATE Flag for bindService(Intent, ServiceConnection, int) : automatically create the service as long as the binding exists.
int BIND_DEBUG_UNBIND Flag for bindService(Intent, ServiceConnection, int) : include debugging help for mismatched calls to unbind.
int BIND_IMPORTANT Flag for bindService(Intent, ServiceConnection, int) : this service is very important to the client, so should be brought to the foreground process level when the client is.
int BIND_NOT_FOREGROUND Flag for bindService(Intent, ServiceConnection, int) : don't allow this binding to raise the target service's process to the foreground scheduling priority.
int BIND_WAIVE_PRIORITY Flag for bindService(Intent, ServiceConnection, int) : don't impact the scheduling or memory management priority of the target service's hosting process.
String BLUETOOTH_SERVICE Use with getSystemService(String) to retrieve a BluetoothAdapter for using Bluetooth.
String CAPTIONING_SERVICE Use with getSystemService(String) to retrieve a CaptioningManager for obtaining captioning properties and listening for changes in captioning preferences.
String CLIPBOARD_SERVICE Use with getSystemService(String) to retrieve a ClipboardManager for accessing and modifying the contents of the global clipboard.
String CONNECTIVITY_SERVICE Use with getSystemService(String) to retrieve a ConnectivityManager for handling management of network connections.
String CONSUMER_IR_SERVICE Use with getSystemService(String) to retrieve a ConsumerIrManager for transmitting infrared signals from the device.
int CONTEXT_IGNORE_SECURITY Flag for use with createPackageContext(String, int) : ignore any security restrictions on the Context being requested, allowing it to always be loaded.
int CONTEXT_INCLUDE_CODE Flag for use with createPackageContext(String, int) : include the application code with the context.
int CONTEXT_RESTRICTED Flag for use with createPackageContext(String, int) : a restricted context may disable specific features.
String DEVICE_POLICY_SERVICE Use with getSystemService(String) to retrieve a DevicePolicyManager for working with global device policy management.
String DISPLAY_SERVICE Use with getSystemService(String) to retrieve a DisplayManager for interacting with display devices.
String DOWNLOAD_SERVICE Use with getSystemService(String) to retrieve a DownloadManager for requesting HTTP downloads.
String DROPBOX_SERVICE Use with getSystemService(String) to retrieve a DropBoxManager instance for recording diagnostic logs.
String INPUT_METHOD_SERVICE Use with getSystemService(String) to retrieve a InputMethodManager for accessing input methods.
String INPUT_SERVICE Use with getSystemService(String) to retrieve a InputManager for interacting with input devices.
String KEYGUARD_SERVICE Use with getSystemService(String) to retrieve a NotificationManager for controlling keyguard.
String LAYOUT_INFLATER_SERVICE Use with getSystemService(String) to retrieve a LayoutInflater for inflating layout resources in this context.
String LOCATION_SERVICE Use with getSystemService(String) to retrieve a LocationManager for controlling location updates.
String MEDIA_ROUTER_SERVICE Use with getSystemService(String) to retrieve a MediaRouter for controlling and managing routing of media.
int MODE_APPEND File creation mode: for use with openFileOutput(String, int) , 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.
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 This constant was deprecated in API level 17. Creating world-readable files is very dangerous, and likely to cause security holes in applications. It is strongly discouraged; instead, applications should use more formal mechanism for interactions such as ContentProvider , BroadcastReceiver , and Service . There are no guarantees that this access mode will remain on a file, such as when it goes through a backup and restore. File creation mode: allow all other applications to have read access to the created file.
int MODE_WORLD_WRITEABLE This constant was deprecated in API level 17. Creating world-writable files is very dangerous, and likely to cause security holes in applications. It is strongly discouraged; instead, applications should use more formal mechanism for interactions such as ContentProvider , BroadcastReceiver , and Service . There are no guarantees that this access mode will remain on a file, such as when it goes through a backup and restore. File creation mode: allow all other applications to have write access to the created file.
String NFC_SERVICE Use with getSystemService(String) to retrieve a NfcManager for using NFC.
String NOTIFICATION_SERVICE Use with getSystemService(String) to retrieve a NotificationManager for informing the user of background events.
String NSD_SERVICE Use with getSystemService(String) to retrieve a NsdManager for handling management of network service discovery
String POWER_SERVICE Use with getSystemService(String) to retrieve a PowerManager for controlling power management, including "wake locks," which let you keep the device on while you're running long tasks.
String PRINT_SERVICE PrintManager for printing and managing printers and print tasks.
String SEARCH_SERVICE Use with getSystemService(String) to retrieve a SearchManager for handling searches.
String SENSOR_SERVICE Use with getSystemService(String) to retrieve a SensorManager for accessing sensors.
String STORAGE_SERVICE Use with getSystemService(String) to retrieve a StorageManager for accessing system storage functions.
String TELEPHONY_SERVICE Use with getSystemService(String) to retrieve a TelephonyManager for handling management the telephony features of the device.
String TEXT_SERVICES_MANAGER_SERVICE Use with getSystemService(String) to retrieve a TextServicesManager for accessing text services.
String UI_MODE_SERVICE Use with getSystemService(String) to retrieve a UiModeManager for controlling UI modes.
String USB_SERVICE Use with getSystemService(String) to retrieve a UsbManager 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(String) to retrieve a UserManager for managing users on devices that support multiple users.
String VIBRATOR_SERVICE Use with getSystemService(String) to retrieve a Vibrator for interacting with the vibration hardware.
String WALLPAPER_SERVICE Use with getSystemService(String) to retrieve a com.android.server.WallpaperService for accessing wallpapers.
String WIFI_P2P_SERVICE Use with getSystemService(String) to retrieve a WifiP2pManager for handling management of Wi-Fi peer-to-peer connections.
String WIFI_SERVICE Use with getSystemService(String) to retrieve a WifiManager for handling management of Wi-Fi access.
String WINDOW_SERVICE Use with getSystemService(String) to retrieve a WindowManager for accessing the system's window manager.
Public Constructors
Connect to an application service, creating it if needed. Determine whether the calling process of an IPC or you have been granted a particular permission.

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

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

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

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

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

Check both a Uri and normal permission. This method was deprecated in API level 5. Use WallpaperManager.clear() instead.

This method requires the caller to hold the permission SET_WALLPAPER .

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

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

Return a new Context object for the given application name.

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

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

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

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

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

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

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

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

Enforce both a Uri and normal permission.

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

Return the context of the single, global Application object of the current process. Return the full application info for this context's package. Return an AssetManager instance for your application's package. Returns the absolute path to the application specific cache directory on the filesystem. Return a class loader you can use to retrieve classes in this package. Return a ContentResolver instance for your application's package.

Returns the absolute path on the filesystem where a database created with openOrCreateDatabase(String, int, SQLiteDatabase.CursorFactory) is stored.

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

Returns the absolute path to the directory on the primary external filesystem (that is somewhere on Environment.getExternalStorageDirectory() where the application can place cache files it owns.

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

Returns the absolute path to the directory on the primary external filesystem (that is somewhere on Environment.getExternalStorageDirectory() ) where the application can place persistent files it owns.

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

Returns the absolute path on the filesystem where a file created with openFileOutput(String, int) is stored.

Returns the absolute path to the directory on the filesystem where files created with openFileOutput(String, int) are stored.

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

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

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

Return the full path to this context's primary Android package. Return PackageManager instance to find global package information. Return the name of this application's package. Return the full path to this context's primary Android package. Return a Resources instance for your application's package.

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

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

Return a localized formatted string from the application's package's default string table, substituting the format arguments as defined in Formatter and format(String, Object. ) .

Return the handle to a system-level service by name. Return a localized, styled CharSequence from the application's package's default string table. Return the Theme object associated with this Context. This method was deprecated in API level 5. Use WallpaperManager.get() instead. This method was deprecated in API level 5. Use WallpaperManager.getDesiredMinimumHeight() instead. This method was deprecated in API level 5. Use WallpaperManager.getDesiredMinimumWidth() instead.

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

Indicates whether this Context is restricted. Retrieve styled attribute information in this Context's theme. Retrieve styled attribute information in this Context's theme. Retrieve styled attribute information in this Context's theme. Retrieve styled attribute information in this Context's theme. Open a private file associated with this Context's application package for reading. Open a private file associated with this Context's application package for writing. Open a new private SQLiteDatabase associated with this Context's application package. Open a new private SQLiteDatabase associated with this Context's application package. This method was deprecated in API level 5. Use WallpaperManager.peek() instead.

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.

Register a BroadcastReceiver to be run in the main activity thread. Register to receive intent broadcasts, to run in the context of scheduler .

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

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

Remove all permissions to access a particular content provider Uri that were previously added with grantUriPermission(String, Uri, int) .

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

Broadcast the given intent to all interested BroadcastReceivers. Version of sendBroadcast(Intent) that allows you to specify the user the broadcast will be sent to.

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

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

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.

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

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

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

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

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

Set the base theme for this context. This method was deprecated in API level 5. Use WallpaperManager.set() instead.

This method requires the caller to hold the permission SET_WALLPAPER .

This method was deprecated in API level 5. Use WallpaperManager.set() instead.

This method requires the caller to hold the permission SET_WALLPAPER .

Launch multiple new activities. Same as startActivities(Intent[], Bundle) with no options specified. Same as startActivity(Intent, Bundle) with no options specified. Launch a new activity. Start executing an Instrumentation class. Like startActivity(Intent, Bundle) , but taking a IntentSender to start. Same as startIntentSender(IntentSender, Intent, int, int, int, Bundle) with no options specified. Request that a given application service be started. Request that a given application service be stopped. Disconnect from an application service. Unregister a previously registered BroadcastReceiver. Inherited Methods Creates and returns a copy of this Object . Compares this instance with the specified object and indicates if they are equal. Invoked when the garbage collector has detected that this instance is no longer reachable. Returns the unique instance of Class that represents this object's class. Returns an integer hash code for this object.

Causes a thread which is waiting on this object's monitor (by means of calling one of the wait() methods) to be woken up.

Causes all threads which are waiting on this object's monitor (by means of calling one of the wait() methods) to be woken up.

Returns a string containing a concise, human-readable description of this object.

Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object.

Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the specified timeout expires.

Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the specified timeout expires.

Constants

public static final String ACCESSIBILITY_SERVICE

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

See Also
Constant Value: "accessibility"

public static final String ACCOUNT_SERVICE

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

See Also
Constant Value: "account"

public static final String ACTIVITY_SERVICE

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

See Also
Constant Value: "activity"

public static final String ALARM_SERVICE

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

See Also
Constant Value: "alarm"

public static final String APP_OPS_SERVICE

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

See Also
Constant Value: "appops"

public static final String AUDIO_SERVICE

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

See Also
Constant Value: "audio"

public static final int BIND_ABOVE_CLIENT

Flag for bindService(Intent, ServiceConnection, int) : 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.

Constant Value: 8 (0x00000008)

public static final int BIND_ADJUST_WITH_ACTIVITY

Flag for bindService(Intent, ServiceConnection, int) : 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.

Constant Value: 128 (0x00000080)

public static final int BIND_ALLOW_OOM_MANAGEMENT

Flag for bindService(Intent, ServiceConnection, int) : 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.

Constant Value: 16 (0x00000010)

public static final int BIND_AUTO_CREATE

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

Note that prior to 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.

Constant Value: 1 (0x00000001)

public static final int BIND_DEBUG_UNBIND

Flag for bindService(Intent, ServiceConnection, int) : include debugging help for mismatched calls to unbind. When this flag is set, the callstack of the following unbindService(ServiceConnection) 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.

Constant Value: 2 (0x00000002)

public static final int BIND_IMPORTANT

Flag for bindService(Intent, ServiceConnection, int) : 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.

Constant Value: 64 (0x00000040)

public static final int BIND_NOT_FOREGROUND

Flag for bindService(Intent, ServiceConnection, int) : 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.

Constant Value: 4 (0x00000004)

public static final int BIND_WAIVE_PRIORITY

Flag for bindService(Intent, ServiceConnection, int) : 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.

Constant Value: 32 (0x00000020)

public static final String BLUETOOTH_SERVICE

Use with getSystemService(String) to retrieve a BluetoothAdapter for using Bluetooth.

See Also