Java android.content Context fields, constructors, methods, implement or subclass

Example usage for Java android.content Context fields, constructors, methods, implement or subclass

Introduction

In this page you can find the methods, fields and constructors for android.content Context.

The text is from its open source code.

Subclass

android.content.Context has subclasses.
Click this link to see all its subclasses.

Field

intMODE_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).
intMODE_WORLD_READABLE
File creation mode: allow all other applications to have read access to the created file.
intMODE_WORLD_WRITEABLE
File creation mode: allow all other applications to have write access to the created file.
intMODE_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.
intMODE_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.
intBIND_AUTO_CREATE
Flag for #bindService : automatically create the service as long as the binding exists.
intBIND_DEBUG_UNBIND
Flag for #bindService : include debugging help for mismatched calls to unbind.
intBIND_NOT_FOREGROUND
Flag for #bindService : don't allow this binding to raise the target service's process to the foreground scheduling priority.
intBIND_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.
intBIND_WAIVE_PRIORITY
Flag for #bindService : don't impact the scheduling or memory management priority of the target service's hosting process.
intBIND_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.
intBIND_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.
StringPOWER_SERVICE
Use with #getSystemService(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.
StringWINDOW_SERVICE
Use with #getSystemService(String) to retrieve a android.view.WindowManager for accessing the system's window manager.
StringLAYOUT_INFLATER_SERVICE
Use with #getSystemService(String) to retrieve a android.view.LayoutInflater for inflating layout resources in this context.
StringACCOUNT_SERVICE
Use with #getSystemService(String) to retrieve a android.accounts.AccountManager for receiving intents at a time of your choosing.
StringACTIVITY_SERVICE
Use with #getSystemService(String) to retrieve a android.app.ActivityManager for interacting with the global system state.
StringALARM_SERVICE
Use with #getSystemService(String) to retrieve a android.app.AlarmManager for receiving intents at a time of your choosing.
StringNOTIFICATION_SERVICE
Use with #getSystemService(String) to retrieve a android.app.NotificationManager for informing the user of background events.
StringACCESSIBILITY_SERVICE
Use with #getSystemService(String) to retrieve a android.view.accessibility.AccessibilityManager for giving the user feedback for UI events through the registered event listeners.
StringCAPTIONING_SERVICE
Use with #getSystemService(String) to retrieve a android.view.accessibility.CaptioningManager for obtaining captioning properties and listening for changes in captioning preferences.
StringKEYGUARD_SERVICE
Use with #getSystemService(String) to retrieve a android.app.KeyguardManager for controlling keyguard.
StringLOCATION_SERVICE
Use with #getSystemService(String) to retrieve a android.location.LocationManager for controlling location updates.
StringCOUNTRY_DETECTOR
Use with #getSystemService(String) to retrieve a android.location.CountryDetector for detecting the country that the user is in.
StringSEARCH_SERVICE
Use with #getSystemService(String) to retrieve a android.app.SearchManager for handling searches.
StringSENSOR_SERVICE
Use with #getSystemService(String) to retrieve a android.hardware.SensorManager for accessing sensors.
StringSTORAGE_SERVICE
Use with #getSystemService(String) to retrieve a android.os.storage.StorageManager for accessing system storage functions.
StringWALLPAPER_SERVICE
Use with #getSystemService(String) to retrieve a com.android.server.WallpaperService for accessing wallpapers.
StringVIBRATOR_SERVICE
Use with #getSystemService(String) to retrieve a android.os.Vibrator for interacting with the vibration hardware.
StringSTATUS_BAR_SERVICE
Use with #getSystemService(String) to retrieve a android.app.StatusBarManager for interacting with the status bar.
StringCONNECTIVITY_SERVICE
Use with #getSystemService(String) to retrieve a android.net.ConnectivityManager for handling management of network connections.
StringNETWORKMANAGEMENT_SERVICE
Constant for the internal network management service, not really a Context service.
StringNETWORK_STATS_SERVICE
Use with #getSystemService(String) to retrieve a android.app.usage.NetworkStatsManager for querying network usage stats.
StringWIFI_SERVICE
Use with #getSystemService(String) to retrieve a android.net.wifi.WifiManager for handling management of Wi-Fi access.
StringWIFI_P2P_SERVICE
Use with #getSystemService(String) to retrieve a android.net.wifi.p2p.WifiP2pManager for handling management of Wi-Fi peer-to-peer connections.
StringNSD_SERVICE
Use with #getSystemService(String) to retrieve a android.net.nsd.NsdManager for handling management of network service discovery
StringAUDIO_SERVICE
Use with #getSystemService(String) to retrieve a android.media.AudioManager for handling management of volume, ringer modes and audio routing.
StringFINGERPRINT_SERVICE
Use with #getSystemService(String) to retrieve a android.hardware.fingerprint.FingerprintManager for handling management of fingerprints.
StringMEDIA_ROUTER_SERVICE
Use with #getSystemService(String) to retrieve a android.media.MediaRouter for controlling and managing routing of media.
StringMEDIA_SESSION_SERVICE
Use with #getSystemService(String) to retrieve a android.media.session.MediaSessionManager for managing media Sessions.
StringTELEPHONY_SERVICE
Use with #getSystemService(String) to retrieve a android.telephony.TelephonyManager for handling management the telephony features of the device.
StringTELEPHONY_SUBSCRIPTION_SERVICE
Use with #getSystemService(String) to retrieve a android.telephony.SubscriptionManager for handling management the telephony subscriptions of the device.
StringTELECOM_SERVICE
Use with #getSystemService(String) to retrieve a android.telecom.TelecomManager to manage telecom-related features of the device.
StringCARRIER_CONFIG_SERVICE
Use with #getSystemService(String) to retrieve a android.telephony.CarrierConfigManager for reading carrier configuration values.
StringCLIPBOARD_SERVICE
Use with #getSystemService(String) to retrieve a android.content.ClipboardManager for accessing and modifying the contents of the global clipboard.
StringINPUT_METHOD_SERVICE
Use with #getSystemService(String) to retrieve a android.view.inputmethod.InputMethodManager for accessing input methods.
StringTEXT_SERVICES_MANAGER_SERVICE
Use with #getSystemService(String) to retrieve a android.view.textservice.TextServicesManager for accessing text services.
StringAPPWIDGET_SERVICE
Use with #getSystemService(String) to retrieve a android.appwidget.AppWidgetManager for accessing AppWidgets.
StringDEVICE_POLICY_SERVICE
Use with #getSystemService(String) to retrieve a android.app.admin.DevicePolicyManager for working with global device policy management.
StringUI_MODE_SERVICE
Use with #getSystemService(String) to retrieve a android.app.UiModeManager for controlling UI modes.
StringDOWNLOAD_SERVICE
Use with #getSystemService(String) to retrieve a android.app.DownloadManager for requesting HTTP downloads.
StringBATTERY_SERVICE
Use with #getSystemService(String) to retrieve a android.os.BatteryManager for managing battery state.
StringNFC_SERVICE
Use with #getSystemService(String) to retrieve a android.nfc.NfcManager for using NFC.
StringBLUETOOTH_SERVICE
Use with #getSystemService(String) to retrieve a android.bluetooth.BluetoothManager for using Bluetooth.
StringUSB_SERVICE
Use with #getSystemService(String) to retrieve a android.hardware.usb.UsbManager for access to USB devices (as a USB host) and for controlling this device's behavior as a USB device.
StringINPUT_SERVICE
Use with #getSystemService(String) to retrieve a android.hardware.input.InputManager for interacting with input devices.
StringDISPLAY_SERVICE
Use with #getSystemService(String) to retrieve a android.hardware.display.DisplayManager for interacting with display devices.
StringUSER_SERVICE
Use with #getSystemService(String) to retrieve a android.os.UserManager for managing users on devices that support multiple users.
StringLAUNCHER_APPS_SERVICE
Use with #getSystemService(String) to retrieve a android.content.pm.LauncherApps for querying and monitoring launchable apps across profiles of a user.
StringRESTRICTIONS_SERVICE
Use with #getSystemService(String) to retrieve a android.content.RestrictionsManager for retrieving application restrictions and requesting permissions for restricted operations.
StringAPP_OPS_SERVICE
Use with #getSystemService(String) to retrieve a android.app.AppOpsManager for tracking application operations on the device.
StringCAMERA_SERVICE
Use with #getSystemService(String) to retrieve a android.hardware.camera2.CameraManager for interacting with camera devices.
StringPRINT_SERVICE
android.print.PrintManager for printing and managing printers and print tasks.
StringCONSUMER_IR_SERVICE
Use with #getSystemService(String) to retrieve a android.hardware.ConsumerIrManager for transmitting infrared signals from the device.
StringTV_INPUT_SERVICE
Use with #getSystemService(String) to retrieve a android.media.tv.TvInputManager for interacting with TV inputs on the device.
StringUSAGE_STATS_SERVICE
Use with #getSystemService(String) to retrieve a android.app.usage.UsageStatsManager for querying device usage stats.
StringJOB_SCHEDULER_SERVICE
Use with #getSystemService(String) to retrieve a android.app.job.JobScheduler instance for managing occasional background tasks.
StringMEDIA_PROJECTION_SERVICE
Use with #getSystemService(String) to retrieve a android.media.projection.MediaProjectionManager instance for managing media projection sessions.
StringRADIO_SERVICE
Use with #getSystemService(String) to retrieve a android.hardware.radio.RadioManager for accessing the broadcast radio service.
StringSHORTCUT_SERVICE
Use with #getSystemService(String) to retrieve a android.content.pm.ShortcutManager for accessing the launcher shortcut service.
intCONTEXT_INCLUDE_CODE
Flag for use with #createPackageContext : include the application code with the context.
intCONTEXT_IGNORE_SECURITY
Flag for use with #createPackageContext : ignore any security restrictions on the Context being requested, allowing it to always be loaded.
intCONTEXT_RESTRICTED
Flag for use with #createPackageContext : a restricted context may disable specific features.

Method

booleanbindService(@RequiresPermission Intent service, @NonNull ServiceConnection conn, @BindServiceFlags int flags)
Connect to an application service, creating it if needed.
intcheckCallingOrSelfPermission(@NonNull String permission)
Determine whether the calling process of an IPC or you have been granted a particular permission.
intcheckCallingOrSelfUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags)
Determine whether the calling process of an IPC or you has been granted permission to access a specific URI.
intcheckCallingPermission(@NonNull String permission)
Determine whether the calling process of an IPC you are handling has been granted a particular permission.
intcheckPermission(@NonNull String permission, int pid, int uid)
Determine whether the given permission is allowed for a particular process and user ID running in the system.
intcheckSelfPermission(@NonNull String permission)
Determine whether you have been granted a particular permission.
ContextcreateConfigurationContext(@NonNull Configuration overrideConfiguration)
Return a new Context object for the current Context but whose resources are adjusted to match the given Configuration.
ContextcreateDeviceProtectedStorageContext()
Return a new Context object for the current Context but whose storage APIs are backed by device-protected storage.
ContextcreatePackageContext(String packageName, @CreatePackageOptions int flags)
Return a new Context object for the given application name.
String[]databaseList()
Returns an array of strings naming the private databases associated with this Context's application package.
booleandeleteDatabase(String name)
Delete an existing private SQLiteDatabase associated with this Context's application package.
booleandeleteFile(String name)
Delete the given private file associated with this Context's application package.
booleanequals(Object obj)
Indicates whether some other object is "equal to" this one.
String[]fileList()
Returns an array of strings naming the private files associated with this Context's application package.
ContextgetApplicationContext()
Return the context of the single, global Application object of the current process.
ApplicationInfogetApplicationInfo()
Return the full application info for this context's package.
AssetManagergetAssets()
Returns an AssetManager instance for the application's package.
FilegetCacheDir()
Returns the absolute path to the application specific cache directory on the filesystem.
ClassgetClass()
Returns the runtime class of this Object .
ClassLoadergetClassLoader()
Return a class loader you can use to retrieve classes in this package.
intgetColor(@ColorRes int id)
Returns a color associated with a particular resource ID and styled for the current theme.
ColorStateListgetColorStateList(@ColorRes int id)
Returns a color state list associated with a particular resource ID and styled for the current theme.
ContentResolvergetContentResolver()
Return a ContentResolver instance for your application's package.
FilegetDatabasePath(String name)
Returns the absolute path on the filesystem where a database created with #openOrCreateDatabase is stored.
FilegetDir(String name, @FileMode int mode)
Retrieve, creating if needed, a new directory in which the application can place its own custom data files.
DrawablegetDrawable(@DrawableRes int id)
Returns a drawable object associated with a particular resource ID and styled for the current theme.
FilegetExternalCacheDir()
Returns absolute path to application-specific directory on the primary shared/external storage device where the application can place cache files it owns.
File[]getExternalCacheDirs()
Returns absolute paths to application-specific directories on all shared/external storage devices where the application can place cache files it owns.
FilegetExternalFilesDir(@Nullable String type)
Returns the absolute path to the directory on the primary shared/external storage device where the application can place persistent files it owns.
File[]getExternalFilesDirs(String type)
Returns absolute paths to application-specific directories on all shared/external storage devices where the application can place persistent files it owns.
File[]getExternalMediaDirs()
Returns absolute paths to application-specific directories on all shared/external storage devices where the application can place media files.
FilegetFilesDir()
Returns the absolute path to the directory on the filesystem where files created with #openFileOutput are stored.
FilegetFileStreamPath(String name)
Returns the absolute path on the filesystem where a file created with #openFileOutput is stored.
LoopergetMainLooper()
Return the Looper for the main thread of the current process.
FilegetNoBackupFilesDir()
Returns the absolute path to the directory on the filesystem similar to #getFilesDir() .
FilegetObbDir()
Return the primary shared/external storage directory where this application's OBB files (if there are any) can be found.
StringgetPackageCodePath()
Return the full path to this context's primary Android package.
PackageManagergetPackageManager()
Return PackageManager instance to find global package information.
StringgetPackageName()
Return the name of this application's package.
StringgetPackageResourcePath()
Return the full path to this context's primary Android package.
ResourcesgetResources()
Returns a Resources instance for the application's package.
SharedPreferencesgetSharedPreferences(String name, @PreferencesMode int mode)
Retrieve and hold the contents of the preferences file 'name', returning a SharedPreferences through which you can retrieve and modify its values.
SharedPreferencesgetSharedPreferences(File file, @PreferencesMode int mode)
Retrieve and hold the contents of the preferences file, returning a SharedPreferences through which you can retrieve and modify its values.
StringgetString(@StringRes int resId)
Returns a localized string from the application's package's default string table.
StringgetString(@StringRes int resId, Object... formatArgs)
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 .
ObjectgetSystemService(@ServiceName @NonNull String name)
Return the handle to a system-level service by name.
TgetSystemService(@NonNull Class serviceClass)
Return the handle to a system-level service by class.
CharSequencegetText(@StringRes int resId)
Return a localized, styled CharSequence from the application's package's default string table.
Resources.ThemegetTheme()
Return the Theme object associated with this Context.
intgetThemeResId()
voidgrantUriPermission(String toPackage, Uri uri, @Intent.GrantUriMode int modeFlags)
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.
booleanisRestricted()
Indicates whether this Context is restricted.
booleanmoveSharedPreferencesFrom(Context sourceContext, String name)
Move an existing shared preferences file from the given source storage context to this context.
TypedArrayobtainStyledAttributes(@StyleableRes int[] attrs)
Retrieve styled attribute information in this Context's theme.
TypedArrayobtainStyledAttributes(@StyleRes int resid, @StyleableRes int[] attrs)
Retrieve styled attribute information in this Context's theme.
TypedArrayobtainStyledAttributes(AttributeSet set, @StyleableRes int[] attrs)
Retrieve styled attribute information in this Context's theme.
TypedArrayobtainStyledAttributes(AttributeSet set, @StyleableRes int[] attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes)
Retrieve styled attribute information in this Context's theme.
FileInputStreamopenFileInput(String name)
Open a private file associated with this Context's application package for reading.
FileOutputStreamopenFileOutput(String name, @FileMode int mode)
Open a private file associated with this Context's application package for writing.
SQLiteDatabaseopenOrCreateDatabase(String name, @DatabaseMode int mode, CursorFactory factory)
Open a new private SQLiteDatabase associated with this Context's application package.
voidregisterComponentCallbacks(ComponentCallbacks callback)
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.
IntentregisterReceiver(@Nullable BroadcastReceiver receiver, IntentFilter filter)
Register a BroadcastReceiver to be run in the main activity thread.
IntentregisterReceiver(BroadcastReceiver receiver, IntentFilter filter, @Nullable String broadcastPermission, @Nullable Handler scheduler)
Register to receive intent broadcasts, to run in the context of scheduler.
voidsendBroadcast(@RequiresPermission Intent intent)
Broadcast the given intent to all interested BroadcastReceivers.
voidsendBroadcast(@RequiresPermission Intent intent, @Nullable String receiverPermission)
Broadcast the given intent to all interested BroadcastReceivers, allowing an optional required permission to be enforced.
voidsendBroadcastAsUser(@RequiresPermission Intent intent, UserHandle user)
Version of #sendBroadcast(Intent) that allows you to specify the user the broadcast will be sent to.
voidsendOrderedBroadcast(@RequiresPermission Intent intent, @Nullable String receiverPermission)
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.
voidsendOrderedBroadcast(@RequiresPermission @NonNull Intent intent, @Nullable String receiverPermission, @Nullable BroadcastReceiver resultReceiver, @Nullable Handler scheduler, int initialCode, @Nullable String initialData, @Nullable Bundle initialExtras)
Version of #sendBroadcast(Intent) that allows you to receive data back from the broadcast.
voidsetTheme(@StyleRes int resid)
Set the base theme for this context.
voidsetWallpaper(Bitmap bitmap)
voidsetWallpaper(InputStream data)
voidstartActivity(@RequiresPermission Intent intent)
Same as #startActivity(Intent,Bundle) with no options specified.
ComponentNamestartForegroundService(Intent service)
Similar to #startService(Intent) , but with an implicit promise that the Service will call android.app.Service#startForeground(int,android.app.Notification) startForeground(int, android.app.Notification) once it begins running.
ComponentNamestartService(Intent service)
Request that a given application service be started.
ComponentNamestartServiceAsUser(Intent service, UserHandle user)
booleanstopService(Intent service)
Request that a given application service be stopped.
StringtoString()
Returns a string representation of the object.
voidunbindService(@NonNull ServiceConnection conn)
Disconnect from an application service.
voidunregisterReceiver(BroadcastReceiver receiver)
Unregister a previously registered BroadcastReceiver.