added in version 22.1.0
belongs to Maven artifact com.android.support:support-compat:28.0.0-alpha1

ContextCompat

public class ContextCompat
extends Object

java.lang.Object
   ↳ android.support.v4.content.ContextCompat
Known Direct Subclasses
Known Indirect Subclasses


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 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 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 File getNoBackupFilesDir(Context context)

Returns the absolute path to the directory on the filesystem similar to 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