androidx.core.content

Interfaces

OnConfigurationChangedProvider

Interface for components that can dispatch calls from ComponentCallbacks.onConfigurationChanged.

OnTrimMemoryProvider

Interface for components that can dispatch calls from ComponentCallbacks2.onTrimMemory.

Classes

ContentProviderCompat

Helper for accessing features in android.content.ContentProvider in a backwards compatible fashion.

ContentResolverCompat

Helper for accessing features in ContentResolver in a backwards compatible fashion.

ContextCompat

Helper for accessing features in Context.

FileProvider

FileProvider is a special subclass of ContentProvider that facilitates secure sharing of files associated with an app by creating a content://Uri for a file instead of a file:///Uri.

IntentCompat

Helper for accessing features in Intent.

IntentSanitizer

This class is used to make a sanitized copy of an Intent.

IntentSanitizer.Builder

General strategy of building is to only offer additive “or” operations that are chained together.

LocusIdCompat

An identifier for an unique state (locus) in the application.

MimeTypeFilter

Provides utility methods for matching MIME type filters used in ContentProvider.

PackageManagerCompat

Helper for accessing features in PackageManager.

PermissionChecker

This class provides permission check APIs that verify both the permission and the associated app op for this permission if such is defined.

SharedPreferencesCompat

This class is deprecated.

This compatibility class is no longer required.

SharedPreferencesCompat.EditorCompat

This class is deprecated.

This compatibility class is no longer required.

UnusedAppRestrictionsBackportCallback

Wrapper class for {IUnusedAppRestrictionsBackportCallback}.

UnusedAppRestrictionsBackportService

Wrapper class for IUnusedAppRestrictionsBackportService.

UnusedAppRestrictionsConstants

Shared constants related to Unused App Restrictions (e.g. Permission Revocation, App Hibernation).

UriMatcherCompat

Helper for accessing UriMatcher to create Uri Predicate.

Top-level functions summary

ContentValues
contentValuesOf(vararg pairs: Pair<StringAny?>)

Returns a new ContentValues with the given key/value pairs as elements.

Extension functions summary

inline Unit

Allows editing of this preference instance with a call to apply or commit to persist the changes.

inline T?

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

inline Unit
Context.withStyledAttributes(
    resourceId: @StyleRes Int,
    attrs: IntArray,
    block: TypedArray.() -> Unit
)

Executes block on a TypedArray receiver.

inline Unit
Context.withStyledAttributes(
    set: AttributeSet?,
    attrs: IntArray,
    defStyleAttr: @AttrRes Int,
    defStyleRes: @StyleRes Int,
    block: TypedArray.() -> Unit
)

Executes block on a TypedArray receiver.

Top-level functions

contentValuesOf

fun contentValuesOf(vararg pairs: Pair<StringAny?>): ContentValues

Returns a new ContentValues with the given key/value pairs as elements.

Throws
kotlin.IllegalArgumentException

When a value is not a supported type of ContentValues.

Extension functions

edit

inline fun SharedPreferences.edit(commit: Boolean = false, action: SharedPreferences.Editor.() -> Unit): Unit

Allows editing of this preference instance with a call to apply or commit to persist the changes. Default behaviour is apply.

prefs.edit {
putString("key", value)
}

To commit changes:

prefs.edit(commit = true) {
putString("key", value)
}

getSystemService

inline fun <T : Any> Context.getSystemService(): T?

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

See also
getSystemService

withStyledAttributes

inline fun Context.withStyledAttributes(
    resourceId: @StyleRes Int,
    attrs: IntArray,
    block: TypedArray.() -> Unit
): Unit

Executes block on a TypedArray receiver. The TypedArray holds the the values defined by the style resource resourceId which are listed in attrs.

Parameters
attrs: IntArray

The desired attributes. These attribute IDs must be sorted in ascending order.

withStyledAttributes

inline fun Context.withStyledAttributes(
    set: AttributeSet? = null,
    attrs: IntArray,
    defStyleAttr: @AttrRes Int = 0,
    defStyleRes: @StyleRes Int = 0,
    block: TypedArray.() -> Unit
): Unit

Executes block on a TypedArray receiver. The TypedArray holds the attribute values in set that are listed in attrs. In addition, if the given AttributeSet specifies a style class (through the style attribute), that style will be applied on top of the base attributes it defines.

Parameters
set: AttributeSet? = null

The base set of attribute values.

attrs: IntArray

The desired attributes to be retrieved. These attribute IDs must be sorted in ascending order.

defStyleAttr: @AttrRes Int = 0

An attribute in the current theme that contains a reference to a style resource that supplies defaults values for the TypedArray. Can be 0 to not look for defaults.

defStyleRes: @StyleRes Int = 0

A resource identifier of a style resource that supplies default values for the TypedArray, used only if defStyleAttr is 0 or can not be found in the theme. Can be 0 to not look for defaults.