Example usage for Java android.content Context fields, constructors, methods, implement or subclass
The text is from its open source code.
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. |
int | MODE_WORLD_WRITEABLE File creation mode: allow all other applications to have write access to the created file. |
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_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 | BIND_AUTO_CREATE Flag for #bindService : automatically create the service as long as the binding exists. |
int | BIND_DEBUG_UNBIND Flag for #bindService : include debugging help for mismatched calls to unbind. |
int | BIND_NOT_FOREGROUND Flag for #bindService : don't allow this binding to raise the target service's process to the foreground scheduling priority. |
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. |
int | BIND_WAIVE_PRIORITY Flag for #bindService : don't impact the scheduling or memory management priority of the target service's hosting process. |
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. |
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. |
String | POWER_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. |
String | WINDOW_SERVICE Use with #getSystemService(String) to retrieve a android.view.WindowManager for accessing the system's window manager. |
String | LAYOUT_INFLATER_SERVICE Use with #getSystemService(String) to retrieve a android.view.LayoutInflater for inflating layout resources in this context. |
String | ACCOUNT_SERVICE Use with #getSystemService(String) to retrieve a android.accounts.AccountManager for receiving intents at a time of your choosing. |
String | ACTIVITY_SERVICE Use with #getSystemService(String) to retrieve a android.app.ActivityManager for interacting with the global system state. |
String | ALARM_SERVICE Use with #getSystemService(String) to retrieve a android.app.AlarmManager for receiving intents at a time of your choosing. |
String | NOTIFICATION_SERVICE Use with #getSystemService(String) to retrieve a android.app.NotificationManager for informing the user of background events. |
String | ACCESSIBILITY_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. |
String | CAPTIONING_SERVICE Use with #getSystemService(String) to retrieve a android.view.accessibility.CaptioningManager for obtaining captioning properties and listening for changes in captioning preferences. |
String | KEYGUARD_SERVICE Use with #getSystemService(String) to retrieve a android.app.KeyguardManager for controlling keyguard. |
String | LOCATION_SERVICE Use with #getSystemService(String) to retrieve a android.location.LocationManager for controlling location updates. |
String | COUNTRY_DETECTOR Use with #getSystemService(String) to retrieve a android.location.CountryDetector for detecting the country that the user is in. |
String | SEARCH_SERVICE Use with #getSystemService(String) to retrieve a android.app.SearchManager for handling searches. |
String | SENSOR_SERVICE Use with #getSystemService(String) to retrieve a android.hardware.SensorManager for accessing sensors. |
String | STORAGE_SERVICE Use with #getSystemService(String) to retrieve a android.os.storage.StorageManager for accessing system storage functions. |
String | WALLPAPER_SERVICE Use with #getSystemService(String) to retrieve a com.android.server.WallpaperService for accessing wallpapers. |
String | VIBRATOR_SERVICE Use with #getSystemService(String) to retrieve a android.os.Vibrator for interacting with the vibration hardware. |
String | STATUS_BAR_SERVICE Use with #getSystemService(String) to retrieve a android.app.StatusBarManager for interacting with the status bar. |
String | CONNECTIVITY_SERVICE Use with #getSystemService(String) to retrieve a android.net.ConnectivityManager for handling management of network connections. |
String | NETWORKMANAGEMENT_SERVICE Constant for the internal network management service, not really a Context service. |
String | NETWORK_STATS_SERVICE Use with #getSystemService(String) to retrieve a android.app.usage.NetworkStatsManager for querying network usage stats. |
String | WIFI_SERVICE Use with #getSystemService(String) to retrieve a android.net.wifi.WifiManager for handling management of Wi-Fi access. |
String | WIFI_P2P_SERVICE Use with #getSystemService(String) to retrieve a android.net.wifi.p2p.WifiP2pManager for handling management of Wi-Fi peer-to-peer connections. |
String | NSD_SERVICE Use with #getSystemService(String) to retrieve a android.net.nsd.NsdManager for handling management of network service discovery |
String | AUDIO_SERVICE Use with #getSystemService(String) to retrieve a android.media.AudioManager for handling management of volume, ringer modes and audio routing. |
String | FINGERPRINT_SERVICE Use with #getSystemService(String) to retrieve a android.hardware.fingerprint.FingerprintManager for handling management of fingerprints. |
String | MEDIA_ROUTER_SERVICE Use with #getSystemService(String) to retrieve a android.media.MediaRouter for controlling and managing routing of media. |
String | MEDIA_SESSION_SERVICE Use with #getSystemService(String) to retrieve a android.media.session.MediaSessionManager for managing media Sessions. |
String | TELEPHONY_SERVICE Use with #getSystemService(String) to retrieve a android.telephony.TelephonyManager for handling management the telephony features of the device. |
String | TELEPHONY_SUBSCRIPTION_SERVICE Use with #getSystemService(String) to retrieve a android.telephony.SubscriptionManager for handling management the telephony subscriptions of the device. |
String | TELECOM_SERVICE Use with #getSystemService(String) to retrieve a android.telecom.TelecomManager to manage telecom-related features of the device. |
String | CARRIER_CONFIG_SERVICE Use with #getSystemService(String) to retrieve a android.telephony.CarrierConfigManager for reading carrier configuration values. |
String | CLIPBOARD_SERVICE Use with #getSystemService(String) to retrieve a android.content.ClipboardManager for accessing and modifying the contents of the global clipboard. |
String | INPUT_METHOD_SERVICE Use with #getSystemService(String) to retrieve a android.view.inputmethod.InputMethodManager for accessing input methods. |
String | TEXT_SERVICES_MANAGER_SERVICE Use with #getSystemService(String) to retrieve a android.view.textservice.TextServicesManager for accessing text services. |
String | APPWIDGET_SERVICE Use with #getSystemService(String) to retrieve a android.appwidget.AppWidgetManager for accessing AppWidgets. |
String | DEVICE_POLICY_SERVICE Use with #getSystemService(String) to retrieve a android.app.admin.DevicePolicyManager for working with global device policy management. |
String | UI_MODE_SERVICE Use with #getSystemService(String) to retrieve a android.app.UiModeManager for controlling UI modes. |
String | DOWNLOAD_SERVICE Use with #getSystemService(String) to retrieve a android.app.DownloadManager for requesting HTTP downloads. |
String | BATTERY_SERVICE Use with #getSystemService(String) to retrieve a android.os.BatteryManager for managing battery state. |
String | NFC_SERVICE Use with #getSystemService(String) to retrieve a android.nfc.NfcManager for using NFC. |
String | BLUETOOTH_SERVICE Use with #getSystemService(String) to retrieve a android.bluetooth.BluetoothManager for using Bluetooth. |
String | USB_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. |
String | INPUT_SERVICE Use with #getSystemService(String) to retrieve a android.hardware.input.InputManager for interacting with input devices. |
String | DISPLAY_SERVICE Use with #getSystemService(String) to retrieve a android.hardware.display.DisplayManager for interacting with display devices. |
String | USER_SERVICE Use with #getSystemService(String) to retrieve a android.os.UserManager for managing users on devices that support multiple users. |
String | LAUNCHER_APPS_SERVICE Use with #getSystemService(String) to retrieve a android.content.pm.LauncherApps for querying and monitoring launchable apps across profiles of a user. |
String | RESTRICTIONS_SERVICE Use with #getSystemService(String) to retrieve a android.content.RestrictionsManager for retrieving application restrictions and requesting permissions for restricted operations. |
String | APP_OPS_SERVICE Use with #getSystemService(String) to retrieve a android.app.AppOpsManager for tracking application operations on the device. |
String | CAMERA_SERVICE Use with #getSystemService(String) to retrieve a android.hardware.camera2.CameraManager for interacting with camera devices. |
String | PRINT_SERVICE android.print.PrintManager for printing and managing printers and print tasks. |
String | CONSUMER_IR_SERVICE Use with #getSystemService(String) to retrieve a android.hardware.ConsumerIrManager for transmitting infrared signals from the device. |
String | TV_INPUT_SERVICE Use with #getSystemService(String) to retrieve a android.media.tv.TvInputManager for interacting with TV inputs on the device. |
String | USAGE_STATS_SERVICE Use with #getSystemService(String) to retrieve a android.app.usage.UsageStatsManager for querying device usage stats. |
String | JOB_SCHEDULER_SERVICE Use with #getSystemService(String) to retrieve a android.app.job.JobScheduler instance for managing occasional background tasks. |
String | MEDIA_PROJECTION_SERVICE Use with #getSystemService(String) to retrieve a android.media.projection.MediaProjectionManager instance for managing media projection sessions. |
String | RADIO_SERVICE Use with #getSystemService(String) to retrieve a android.hardware.radio.RadioManager for accessing the broadcast radio service. |
String | SHORTCUT_SERVICE Use with #getSystemService(String) to retrieve a android.content.pm.ShortcutManager for accessing the launcher shortcut service. |
int | CONTEXT_INCLUDE_CODE Flag for use with #createPackageContext : include the application code with the context. |
int | CONTEXT_IGNORE_SECURITY Flag for use with #createPackageContext : ignore any security restrictions on the Context being requested, allowing it to always be loaded. |
int | CONTEXT_RESTRICTED Flag for use with #createPackageContext : a restricted context may disable specific features. |
boolean | bindService(@RequiresPermission Intent service, @NonNull ServiceConnection conn, @BindServiceFlags int flags) Connect to an application service, creating it if needed. |
int | checkCallingOrSelfPermission(@NonNull String permission) Determine whether the calling process of an IPC or you have been granted a particular permission. |
int | checkCallingOrSelfUriPermission(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. |
int | checkCallingPermission(@NonNull String permission) Determine whether the calling process of an IPC you are handling has been granted a particular permission. |
int | checkPermission(@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. |
int | checkSelfPermission(@NonNull String permission) Determine whether you have been granted a particular permission. |
Context | createConfigurationContext(@NonNull Configuration overrideConfiguration) Return a new Context object for the current Context but whose resources are adjusted to match the given Configuration. |
Context | createDeviceProtectedStorageContext() Return a new Context object for the current Context but whose storage APIs are backed by device-protected storage. |
Context | createPackageContext(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. |
boolean | deleteDatabase(String name) Delete an existing private SQLiteDatabase associated with this Context's application package. |
boolean | deleteFile(String name) Delete the given private file associated with this Context's application package. |
boolean | equals(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. |
Context | getApplicationContext() Return the context of the single, global Application object of the current process. |
ApplicationInfo | getApplicationInfo() Return the full application info for this context's package. |
AssetManager | getAssets() Returns an AssetManager instance for the application's package. |
File | getCacheDir() Returns the absolute path to the application specific cache directory on the filesystem. |
Class> | getClass() Returns the runtime class of this Object . |
ClassLoader | getClassLoader() Return a class loader you can use to retrieve classes in this package. |
int | getColor(@ColorRes int id) Returns a color associated with a particular resource ID and styled for the current theme. |
ColorStateList | getColorStateList(@ColorRes int id) Returns a color state list associated with a particular resource ID and styled for the current theme. |
ContentResolver | getContentResolver() Return a ContentResolver instance for your application's package. |
File | getDatabasePath(String name) Returns the absolute path on the filesystem where a database created with #openOrCreateDatabase is stored. |
File | getDir(String name, @FileMode int mode) Retrieve, creating if needed, a new directory in which the application can place its own custom data files. |
Drawable | getDrawable(@DrawableRes int id) Returns a drawable object associated with a particular resource ID and styled for the current theme. |
File | getExternalCacheDir() 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. |
File | getExternalFilesDir(@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. |
File | getFilesDir() Returns the absolute path to the directory on the filesystem where files created with #openFileOutput are stored. |
File | getFileStreamPath(String name) Returns the absolute path on the filesystem where a file created with #openFileOutput is stored. |
Looper | getMainLooper() Return the Looper for the main thread of the current process. |
File | getNoBackupFilesDir() Returns the absolute path to the directory on the filesystem similar to #getFilesDir() . |
File | getObbDir() Return the primary shared/external storage directory where this application's OBB files (if there are any) can be found. |
String | getPackageCodePath() Return the full path to this context's primary Android package. |
PackageManager | getPackageManager() Return PackageManager instance to find global package information. |
String | getPackageName() Return the name of this application's package. |
String | getPackageResourcePath() Return the full path to this context's primary Android package. |
Resources | getResources() Returns a Resources instance for the application's package. |
SharedPreferences | getSharedPreferences(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. |
SharedPreferences | getSharedPreferences(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. |
String | getString(@StringRes int resId) Returns a localized string from the application's package's default string table. |
String | getString(@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 . |
Object | getSystemService(@ServiceName @NonNull String name) Return the handle to a system-level service by name. |
T | getSystemService(@NonNull Class Return the handle to a system-level service by class. |
CharSequence | getText(@StringRes int resId) Return a localized, styled CharSequence from the application's package's default string table. |
Resources.Theme | getTheme() Return the Theme object associated with this Context. |
int | getThemeResId() |
void | grantUriPermission(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. |
boolean | isRestricted() Indicates whether this Context is restricted. |
boolean | moveSharedPreferencesFrom(Context sourceContext, String name) Move an existing shared preferences file from the given source storage context to this context. |
TypedArray | obtainStyledAttributes(@StyleableRes int[] attrs) Retrieve styled attribute information in this Context's theme. |
TypedArray | obtainStyledAttributes(@StyleRes int resid, @StyleableRes int[] attrs) Retrieve styled attribute information in this Context's theme. |
TypedArray | obtainStyledAttributes(AttributeSet set, @StyleableRes int[] attrs) Retrieve styled attribute information in this Context's theme. |
TypedArray | obtainStyledAttributes(AttributeSet set, @StyleableRes int[] attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) Retrieve styled attribute information in this Context's theme. |
FileInputStream | openFileInput(String name) Open a private file associated with this Context's application package for reading. |
FileOutputStream | openFileOutput(String name, @FileMode int mode) Open a private file associated with this Context's application package for writing. |
SQLiteDatabase | openOrCreateDatabase(String name, @DatabaseMode int mode, CursorFactory factory) Open a new private SQLiteDatabase associated with this Context's application package. |
void | registerComponentCallbacks(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. |
Intent | registerReceiver(@Nullable BroadcastReceiver receiver, IntentFilter filter) Register a BroadcastReceiver to be run in the main activity thread. |
Intent | registerReceiver(BroadcastReceiver receiver, IntentFilter filter, @Nullable String broadcastPermission, @Nullable Handler scheduler) Register to receive intent broadcasts, to run in the context of scheduler. |
void | sendBroadcast(@RequiresPermission Intent intent) Broadcast the given intent to all interested BroadcastReceivers. |
void | sendBroadcast(@RequiresPermission Intent intent, @Nullable String receiverPermission) Broadcast the given intent to all interested BroadcastReceivers, allowing an optional required permission to be enforced. |
void | sendBroadcastAsUser(@RequiresPermission Intent intent, UserHandle user) Version of #sendBroadcast(Intent) that allows you to specify the user the broadcast will be sent to. |
void | sendOrderedBroadcast(@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. |
void | sendOrderedBroadcast(@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. |
void | setTheme(@StyleRes int resid) Set the base theme for this context. |
void | setWallpaper(Bitmap bitmap) |
void | setWallpaper(InputStream data) |
void | startActivity(@RequiresPermission Intent intent) Same as #startActivity(Intent,Bundle) with no options specified. |
ComponentName | startForegroundService(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. |
ComponentName | startService(Intent service) Request that a given application service be started. |
ComponentName | startServiceAsUser(Intent service, UserHandle user) |
boolean | stopService(Intent service) Request that a given application service be stopped. |
String | toString() Returns a string representation of the object. |
void | unbindService(@NonNull ServiceConnection conn) Disconnect from an application service. |
void | unregisterReceiver(BroadcastReceiver receiver) Unregister a previously registered BroadcastReceiver. |