Android 12 Developer Preview is here! Try it out, and give us your feedback!

androidx.core.content

Classes

ContentProviderCompat

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

ContentResolverCompat

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

ContextCompat

Helper for accessing features in android.content.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 android.content.Intent.

LocusIdCompat

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

MimeTypeFilter

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

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

Top-level functions summary

ContentValues
contentValuesOf(vararg pairs: Pair<String, Any?>)

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

Extension functions summary

For android.content.Context
T?

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

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

Executes block on a TypedArray receiver.

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

Executes block on a TypedArray receiver.

For android.content.SharedPreferences
Unit
SharedPreferences.edit(commit: Boolean = false, action: Editor.() -> Unit)

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

Top-level functions

contentValuesOf

fun contentValuesOf(vararg pairs: Pair<String, Any?>): ContentValues

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

Exceptions
IllegalArgumentException When a value is not a supported type of ContentValues.

Extension functions

edit

inline fun SharedPreferences.edit(
    commit: Boolean = false,
    action: 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 <reified T : Any> Context.getSystemService(): T?

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

withStyledAttributes

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