ContextCompat

public class ContextCompat
extends Object

java.lang.Object
   ↳ androidx.core.content.ContextCompat


Helper for accessing features in Context.

Summary

Protected constructors

ContextCompat()

This class should not be instantiated, but the constructor must be visible for the class to be extended (ex.

Public methods

static int checkSelfPermission(Context context, String permission)

Determine whether you have been granted a particular permission.

static Context createDeviceProtectedStorageContext(Context context)

Return a new Context object for the current Context but whose storage APIs are backed by device-protected storage.

static String getAttributionTag(Context context)

Attribution can be used in complex apps to logically separate parts of the app.

static File getCodeCacheDir(Context context)

Returns the absolute path to the application specific cache directory on the filesystem designed for storing cached code.

static int getColor(Context context, int id)

Returns a color associated with a particular resource ID

Starting in Build.VERSION_CODES.M, the returned color will be styled for the specified Context's theme.

static ColorStateList getColorStateList(Context context, int id)

Returns a color state list associated with a particular resource ID.

static File getDataDir(Context context)

Returns the absolute path to the directory on the filesystem where all private files belonging to this app are stored.

static Drawable getDrawable(Context context, int id)

Returns a drawable object associated with a particular resource ID.

static File[] getExternalCacheDirs(Context context)

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

static File[] getExternalFilesDirs(Context context, String type)

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

static Executor getMainExecutor(Context context)

Return an Executor that will run enqueued tasks on the main thread associated with this context.

static File getNoBackupFilesDir(Context context)

Returns the absolute path to the directory on the filesystem similar to Context.getFilesDir().

static File[] getObbDirs(Context context)

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.

static <T> T getSystemService(Context context, Class<T> serviceClass)

Return the handle to a system-level service by class.

static String getSystemServiceName(Context context, Class<?> serviceClass)

Gets the name of the system-level service that is represented by the specified class.

static boolean isDeviceProtectedStorage(Context context)

Indicates if the storage APIs of this Context are backed by device-encrypted storage.

static boolean startActivities(Context context, Intent[] intents, Bundle options)

Start a set of activities as a synthesized task stack, if able.

static boolean startActivities(Context context, Intent[] intents)

Start a set of activities as a synthesized task stack, if able.

static void startActivity(Context context, Intent intent, Bundle options)

Start an activity with additional launch information, if able.

static void startForegroundService(Context context, Intent intent)

startForegroundService() was introduced in O, just call startService for before O.

Inherited methods