Android Guides | Samples

Android.Content.Context Class

Interface to global information about an application environment.

See Also: Context

Syntax

[Android.Runtime.Register("android/content/Context", DoNotGenerateAcw=true)]
public abstract class Context : Object

Remarks

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.

[Android Documentation]

Requirements

Namespace: Android.Content
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 1

The members of Android.Content.Context are listed below.

See Also: Object

Public Constructors

Protected Constructors

A constructor used when creating managed representations of JNI objects; called by the runtime.

Public Fields

const
AccessibilityServiceString. Use with Context.GetSystemService(String) to retrieve a AccessibilityManager for giving the user feedback for UI events through the registered event listeners.
const
AccountServiceString. Use with Context.GetSystemService(String) to retrieve a AccountManager for receiving intents at a time of your choosing.
const
ActivityServiceString. Use with Context.GetSystemService(String) to retrieve a ActivityManager for interacting with the global system state.
const
AlarmServiceString. Use with Context.GetSystemService(String) to retrieve a AlarmManager for receiving intents at a time of your choosing.
const
AppOpsServiceString. Use with Context.GetSystemService(String) to retrieve a AppOpsManager for tracking application operations on the device.
const
AppwidgetServiceString. Use with Context.GetSystemService(String) to retrieve a AppWidgetManager for accessing AppWidgets.
const
AudioServiceString. Use with Context.GetSystemService(String) to retrieve a AudioManager for handling management of volume, ringer modes and audio routing.
const
BatteryServiceString. Use with Context.GetSystemService(String) to retrieve a BatteryManager for managing battery state.
const
BluetoothServiceString. Use with Context.GetSystemService(String) to retrieve a BluetoothManager for using Bluetooth.
const
CameraServiceString. Use with Context.GetSystemService(String) to retrieve a CameraManager for interacting with camera devices.
const
CaptioningServiceString. Use with Context.GetSystemService(String) to retrieve a CaptioningManager for obtaining captioning properties and listening for changes in captioning preferences.
const
ClipboardServiceString. Use with Context.GetSystemService(String) to retrieve a ClipboardManager for accessing and modifying ClipboardManager for accessing and modifying the contents of the global clipboard.
const
ConnectivityServiceString. Use with Context.GetSystemService(String) to retrieve a ConnectivityManager for handling management of network connections.
const
ConsumerIrServiceString. Use with Context.GetSystemService(String) to retrieve a ConsumerIrManager for transmitting infrared signals from the device.
const
DevicePolicyServiceString. Use with Context.GetSystemService(String) to retrieve a DevicePolicyManager for working with global device policy management.
const
DisplayServiceString. Use with Context.GetSystemService(String) to retrieve a DisplayManager for interacting with display devices.
const
DownloadServiceString. Use with Context.GetSystemService(String) to retrieve a DownloadManager for requesting HTTP downloads.
const
DropboxServiceString. Use with Context.GetSystemService(String) to retrieve a DropBoxManager instance for recording diagnostic logs.
const
InputMethodServiceString. Use with Context.GetSystemService(String) to retrieve a InputMethodManager for accessing input methods.
const
InputServiceString. Use with Context.GetSystemService(String) to retrieve a InputManager for interacting with input devices.
const
JobSchedulerServiceString. Use with Context.GetSystemService(String) to retrieve a JobScheduler instance for managing occasional background tasks.
const
KeyguardServiceString. Use with Context.GetSystemService(String) to retrieve a NotificationManager for controlling keyguard.
const
LauncherAppsServiceString. Use with Context.GetSystemService(String) to retrieve a LauncherApps for querying and monitoring launchable apps across profiles of a user.
const
LayoutInflaterServiceString. Use with Context.GetSystemService(String) to retrieve a LayoutInflater for inflating layout resources in this context.
const
LocationServiceString. Use with Context.GetSystemService(String) to retrieve a LocationManager for controlling location updates.
const
MediaProjectionServiceString. Use with Context.GetSystemService(String) to retrieve a MediaProjectionManager instance for managing media projection sessions.
const
MediaRouterServiceString. Use with Context.GetSystemService(String) to retrieve a MediaRouter for controlling and managing routing of media.
const
MediaSessionServiceString. Use with Context.GetSystemService(String) to retrieve a MediaSessionManager for managing media Sessions.
const
NfcServiceString. Use with Context.GetSystemService(String) to retrieve a NfcManager for using NFC.
const
NotificationServiceString. Use with Context.GetSystemService(String) to retrieve a NotificationManager for informing the user of background events.
const
NsdServiceString. Use with Context.GetSystemService(String) to retrieve a NsdManager for handling management of network service discovery
const
PowerServiceString. Use with Context.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.
const
PrintServiceString. PrintManager for printing and managing printers and print tasks.
const
RestrictionsServiceString. Use with Context.GetSystemService(String) to retrieve a RestrictionsManager for retrieving application restrictions and requesting permissions for restricted operations.
const
SearchServiceString. Use with Context.GetSystemService(String) to retrieve a SearchManager for handling searches.
const
SensorServiceString. Use with Context.GetSystemService(String) to retrieve a SensorManager for accessing sensors.
const
StorageServiceString. Use with Context.GetSystemService(String) to retrieve a StorageManager for accessing system storage functions.
const
TelecomServiceString. Use with Context.GetSystemService(String) to retrieve a TelecomManager to manage telecom-related features of the device.
const
TelephonyServiceString. Use with Context.GetSystemService(String) to retrieve a TelephonyManager for handling management the telephony features of the device.
const
TextServicesManagerServiceString. Use with Context.GetSystemService(String) to retrieve a TextServicesManager for accessing text services.
const
TvInputServiceString. Use with Context.GetSystemService(String) to retrieve a TvInputManager for interacting with TV inputs on the device.
const
UiModeServiceString. Use with Context.GetSystemService(String) to retrieve a UiModeManager for controlling UI modes.
const
UsbServiceString. Use with Context.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.
const
UserServiceString. Use with Context.GetSystemService(String) to retrieve a UserManager for managing users on devices that support multiple users.
const
VibratorServiceString. Use with Context.GetSystemService(String) to retrieve a Vibrator for interacting with the vibration hardware.
const
WallpaperServiceString. Use with Context.GetSystemService(String) to retrieve a com.android.server.
const
WifiP2pServiceString. Use with Context.GetSystemService(String) to retrieve a WifiP2pManager for handling management of Wi-Fi peer-to-peer connections.
const
WifiServiceString. Use with Context.GetSystemService(String) to retrieve a WifiManager for handling management of Wi-Fi access.
const
WindowServiceString. Use with Context.GetSystemService(String) to retrieve a IWindowManager for accessing the system's window manager.

Public Properties

[read-only]
abstract
ApplicationContextContext. Return the context of the single, global Application object of the current process.
[read-only]
abstract
ApplicationInfoApplicationInfo. Return the full application info for this context's package.
[read-only]
abstract
AssetsAssetManager. Return an AssetManager instance for your application's package.
[read-only]
abstract
CacheDirFile. Returns the absolute path to the application specific cache directory on the filesystem.
[read-only]
abstract
ClassLoaderClassLoader. Return a class loader you can use to retrieve classes in this package.
[read-only]
abstract
CodeCacheDirFile. Returns the absolute path to the application specific cache directory on the filesystem designed for storing cached code.
[read-only]
abstract
ContentResolverContentResolver. Return a ContentResolver instance for your application's package.
[read-only]
abstract
ExternalCacheDirFile. Returns the absolute path to the directory on the primary external filesystem (that is somewhere on Environment.ExternalStorageDirectory where the application can place cache files it owns.
[read-only]
abstract
FilesDirFile. Returns the absolute path to the directory on the filesystem where files created with Context.OpenFileOutput(String,FileCreationMode) are stored.
[read-only]
IsRestrictedBoolean. Indicates whether this Context is restricted.
[read-only]
abstract
MainLooperLooper. Return the Looper for the main thread of the current process.
[read-only]
abstract
NoBackupFilesDirFile. Returns the absolute path to the directory on the filesystem similar to Context.FilesDir.
[read-only]
abstract
ObbDirFile. Return the primary external storage directory where this application's OBB files (if there are any) can be found.
[read-only]
abstract
PackageCodePathString. Return the full path to this context's primary Android package.
[read-only]
abstract
PackageManagerPackageManager. Return PackageManager instance to find global package information.
[read-only]
abstract
PackageNameString. Return the name of this application's package.
[read-only]
abstract
PackageResourcePathString. Return the full path to this context's primary Android package.
[read-only]
abstract
ResourcesResources. Return a Resources instance for your application's package.
[read-only]
abstract
ThemeResources+Theme. Return the Theme object associated with this Context.
[read-only]
abstract
WallpaperDrawable.
[read-only]
abstract
WallpaperDesiredMinimumHeightInt32.
[read-only]
abstract
WallpaperDesiredMinimumWidthInt32.

Protected Properties

[read-only]
override
ThresholdClassIntPtr. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.
[read-only]
override
ThresholdTypeType. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Public Methods

abstract
BindService(Intent, IServiceConnection, Bind) : Boolean
Connect to an application service, creating it if needed.
abstract
CheckCallingOrSelfPermission(String) : Permission
Determine whether the calling process of an IPC or you have been granted a particular permission.
abstract
CheckCallingOrSelfUriPermission(Uri, ActivityFlags) : Permission
Determine whether the calling process of an IPC or you has been granted permission to access a specific URI.
abstract
CheckCallingPermission(String) : Permission
Determine whether the calling process of an IPC you are handling has been granted a particular permission.
abstract
CheckCallingUriPermission(Uri, ActivityFlags) : Permission
Determine whether the calling process and user ID has been granted permission to access a specific URI.
abstract
CheckPermission(String, Int32, Int32) : Permission
Determine whether the given permission is allowed for a particular process and user ID running in the system.
abstract
CheckUriPermission(Uri, Int32, Int32, ActivityFlags) : Permission
Determine whether a particular process and user ID has been granted permission to access a specific URI.
abstract
CheckUriPermission(Uri, String, String, Int32, Int32, ActivityFlags) : Permission
Check both a Uri and normal permission.
abstract
ClearWallpaper()
abstract
CreateConfigurationContext(Configuration) : Context
Return a new Context object for the current Context but whose resources are adjusted to match the given Configuration.
abstract
CreateDisplayContext(Display) : Context
Return a new Context object for the current Context but whose resources are adjusted to match the metrics of the given Display.
abstract
CreatePackageContext(String, PackageContextFlags) : Context
Return a new Context object for the given application name.
abstract
DatabaseList() : String[]
Returns an array of strings naming the private databases associated with this Context's application package.
abstract
DeleteDatabase(String) : Boolean
Delete an existing private SQLiteDatabase associated with this Context's application package.
abstract
DeleteFile(String) : Boolean
Delete the given private file associated with this Context's application package.
abstract
EnforceCallingOrSelfPermission(String, String)
If neither you nor the calling process of an IPC you are handling has been granted a particular permission, throw a SecurityException.
abstract
EnforceCallingOrSelfUriPermission(Uri, ActivityFlags, String)
If the calling process of an IPC or you has not been granted permission to access a specific URI, throw SecurityException.
abstract
EnforceCallingPermission(String, String)
If the calling process of an IPC you are handling has not been granted a particular permission, throw a SecurityException.
abstract
EnforceCallingUriPermission(Uri, ActivityFlags, String)
If the calling process and user ID has not been granted permission to access a specific URI, throw SecurityException.
abstract
EnforcePermission(String, Int32, Int32, String)
If the given permission is not allowed for a particular process and user ID running in the system, throw a SecurityException.
abstract
EnforceUriPermission(Uri, Int32, Int32, ActivityFlags, String)
If a particular process and user ID has not been granted permission to access a specific URI, throw SecurityException.
abstract
EnforceUriPermission(Uri, String, String, Int32, Int32, ActivityFlags, String)
Enforce both a Uri and normal permission.
abstract
FileList() : String[]
Returns an array of strings naming the private files associated with this Context's application package.
abstract
GetDatabasePath(String) : File
Returns the absolute path on the filesystem where a database created with Context.OpenOrCreateDatabase(String,FileCreationMode,FileCreationMode) is stored.
abstract
GetDir(String, FileCreationMode) : File
Retrieve, creating if needed, a new directory in which the application can place its own custom data files.
GetDrawable(Int32) : Drawable
Returns a drawable object associated with a particular resource ID and styled for the current theme.
abstract
GetExternalCacheDirs() : File[]
Returns absolute paths to application-specific directories on all external storage devices where the application can place cache files it owns.
abstract
GetExternalFilesDir(String) : File
Returns the absolute path to the directory on the primary external filesystem (that is somewhere on Environment.ExternalStorageDirectory) where the application can place persistent files it owns.
abstract
GetExternalFilesDirs(String) : File[]
Returns absolute paths to application-specific directories on all external storage devices where the application can place persistent files it owns.
abstract
GetExternalMediaDirs() : File[]
Returns absolute paths to application-specific directories on all external storage devices where the application can place media files.
abstract
GetFileStreamPath(String) : File
Returns the absolute path on the filesystem where a file created with Context.OpenFileOutput(String,FileCreationMode) is stored.
abstract
GetObbDirs() : File[]
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.
abstract
GetSharedPreferences(String, FileCreationMode) : ISharedPreferences
Retrieve and hold the contents of the preferences file 'name', returning a SharedPreferences through which you can retrieve and modify its values.
GetString(Int32) : String
Returns a localized string from the application's package's default string table.
GetString(Int32, params Object[]) : String
abstract
GetSystemService(String) : Object
Return the handle to a system-level service by name.
GetText(Int32) : String
GetTextFormatted(Int32) : ICharSequence
Return a localized, styled CharSequence from the application's package's default string table.
abstract
GrantUriPermission(String, Uri, ActivityFlags)
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.
ObtainStyledAttributes(Int32[]) : TypedArray
Retrieve styled attribute information in this Context's theme.
ObtainStyledAttributes(IAttributeSet, Int32[]) : TypedArray
Retrieve styled attribute information in this Context's theme.
ObtainStyledAttributes(Int32, Int32[]) : TypedArray
Retrieve styled attribute information in this Context's theme.
ObtainStyledAttributes(IAttributeSet, Int32[], Int32, Int32) : TypedArray
Retrieve styled attribute information in this Context's theme.
abstract
OpenFileInput(String) : Stream
Open a private file associated with this Context's application package for reading.
abstract
OpenFileOutput(String, FileCreationMode) : Stream
Open a private file associated with this Context's application package for writing.
abstract
OpenOrCreateDatabase(String, FileCreationMode, SQLiteDatabase+ICursorFactory) : SQLiteDatabase
Open a new private SQLiteDatabase associated with this Context's application package.
abstract
OpenOrCreateDatabase(String, FileCreationMode, SQLiteDatabase+ICursorFactory, IDatabaseErrorHandler) : SQLiteDatabase
Open a new private SQLiteDatabase associated with this Context's application package.
abstract
PeekWallpaper() : Drawable
RegisterComponentCallbacks(IComponentCallbacks)
Add a new IComponentCallbacks to the base application of the Context, which will be called at the same times as the ComponentCallbacks methods of activities and other components are called.
abstract
RegisterReceiver(BroadcastReceiver, IntentFilter) : Intent
Register a BroadcastReceiver to be run in the main activity thread.
abstract
RegisterReceiver(BroadcastReceiver, IntentFilter, String, Handler) : Intent
Register to receive intent broadcasts, to run in the context of scheduler.
abstract
RemoveStickyBroadcast(Intent)
abstract
RemoveStickyBroadcastAsUser(Intent, UserHandle)
abstract
RevokeUriPermission(Uri, ActivityFlags)
Remove all permissions to access a particular content provider Uri that were previously added with Context.GrantUriPermission(String,Uri,Uri).
abstract
SendBroadcast(Intent)
Broadcast the given intent to all interested BroadcastReceivers.
abstract
SendBroadcast(Intent, String)
Broadcast the given intent to all interested BroadcastReceivers, allowing an optional required permission to be enforced.
abstract
SendBroadcastAsUser(Intent, UserHandle)
Version of Context.SendBroadcast(Intent) that allows you to specify the user the broadcast will be sent to.
abstract
SendBroadcastAsUser(Intent, UserHandle, String)
Version of Context.SendBroadcast(Intent,String) that allows you to specify the user the broadcast will be sent to.
abstract
SendOrderedBroadcast(Intent, String)
Broadcast the given intent to all interested BroadcastReceivers, delivering them one at a time to allow more preferred receivers to consume the broadcast before it is delivered to less preferred receivers.
abstract
SendOrderedBroadcast(Intent, String, BroadcastReceiver, Handler, Result, String, Bundle)
Version of Context.SendBroadcast(Intent) that allows you to receive data back from the broadcast.
abstract
SendOrderedBroadcastAsUser(Intent, UserHandle, String, BroadcastReceiver, Handler, Result, String, Bundle)
Version of Context.SendOrderedBroadcast(Intent,String,String,String,String,String,String) that allows you to specify the user the broadcast will be sent to.
abstract
SendStickyBroadcast(Intent)
abstract
SendStickyBroadcastAsUser(Intent, UserHandle)
abstract
SendStickyOrderedBroadcast(Intent, BroadcastReceiver, Handler, Result, String, Bundle)
abstract
SendStickyOrderedBroadcastAsUser(Intent, UserHandle, BroadcastReceiver, Handler, Result, String, Bundle)
abstract
SetTheme(Int32)
Set the base theme for this context.
abstract
SetWallpaper(Bitmap)
abstract
SetWallpaper(Stream)
abstract
StartActivities(Intent[])
Same as Context.StartActivities(Intent[],Bundle) with no options specified.
abstract
StartActivities(Intent[], Bundle)
Launch multiple new activities.
abstract
StartActivity(Intent)
Same as Context.StartActivity(Intent,Bundle) with no options specified.
StartActivity(Type)
abstract
StartActivity(Intent, Bundle)
Launch a new activity.
abstract
StartInstrumentation(ComponentName, String, Bundle) : Boolean
Start executing an Instrumentation class.
abstract
StartIntentSender(IntentSender, Intent, ActivityFlags, ActivityFlags, Int32)
Same as Context.StartIntentSender(IntentSender,Intent,Intent,Intent,Intent,Intent) with no options specified.
abstract
StartIntentSender(IntentSender, Intent, ActivityFlags, ActivityFlags, Int32, Bundle)
Like Context.StartActivity(Intent,Bundle), but taking a IntentSender to start.
abstract
StartService(Intent) : ComponentName
Request that a given application service be started.
abstract
StopService(Intent) : Boolean
Request that a given application service be stopped.
abstract
UnbindService(IServiceConnection)
Disconnect from an application service.
UnregisterComponentCallbacks(IComponentCallbacks)
Remove a IComponentCallbacks object that was previously registered with Context.RegisterComponentCallbacks(IComponentCallbacks).
abstract
UnregisterReceiver(BroadcastReceiver)
Unregister a previously registered BroadcastReceiver.