# androidx.core.content

*** ** * ** ***

## Interfaces

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/core/content/OnConfigurationChangedProvider` | Interface for components that can dispatch calls from `https://developer.android.com/reference/android/content/ComponentCallbacks.html#onConfigurationChanged(android.content.res.Configuration)`. |
| `https://developer.android.com/reference/kotlin/androidx/core/content/OnTrimMemoryProvider` | Interface for components that can dispatch calls from `https://developer.android.com/reference/android/content/ComponentCallbacks2.html#onTrimMemory(int)`. |

## Classes

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/core/content/ContentProviderCompat` | Helper for accessing features in `https://developer.android.com/reference/android/content/ContentProvider.html` in a backwards compatible fashion. |
| `https://developer.android.com/reference/kotlin/androidx/core/content/ContentResolverCompat` | Helper for accessing features in `https://developer.android.com/reference/android/content/ContentResolver.html` in a backwards compatible fashion. |
| `https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat` | Helper for accessing features in `https://developer.android.com/reference/android/content/Context.html`. |
| `https://developer.android.com/reference/kotlin/androidx/core/content/FileProvider` | FileProvider is a special subclass of `https://developer.android.com/reference/android/content/ContentProvider.html` that facilitates secure sharing of files associated with an app by creating a `content://``https://developer.android.com/reference/android/net/Uri.html` for a file instead of a `file:///``https://developer.android.com/reference/android/net/Uri.html`. |
| `https://developer.android.com/reference/kotlin/androidx/core/content/IntentCompat` | Helper for accessing features in `https://developer.android.com/reference/android/content/Intent.html`. |
| `https://developer.android.com/reference/kotlin/androidx/core/content/IntentSanitizer` | This class is used to make a sanitized copy of an `https://developer.android.com/reference/android/content/Intent.html`. |
| `https://developer.android.com/reference/kotlin/androidx/core/content/IntentSanitizer.Builder` | General strategy of building is to only offer additive "or" operations that are chained together. |
| `https://developer.android.com/reference/kotlin/androidx/core/content/LocusIdCompat` | An identifier for an unique state (locus) in the application. |
| `https://developer.android.com/reference/kotlin/androidx/core/content/MimeTypeFilter` | Provides utility methods for matching MIME type filters used in ContentProvider. |
| `https://developer.android.com/reference/kotlin/androidx/core/content/PackageManagerCompat` | Helper for accessing features in `https://developer.android.com/reference/android/content/pm/PackageManager.html`. |
| `https://developer.android.com/reference/kotlin/androidx/core/content/PermissionChecker` | This class provides permission check APIs that verify both the permission and the associated app op for this permission if such is defined. |
| `https://developer.android.com/reference/kotlin/androidx/core/content/SharedPreferencesCompat` | **This class is deprecated.** This compatibility class is no longer required. <br /> |
| `https://developer.android.com/reference/kotlin/androidx/core/content/SharedPreferencesCompat.EditorCompat` | **This class is deprecated.** This compatibility class is no longer required. <br /> |
| `https://developer.android.com/reference/kotlin/androidx/core/content/UnusedAppRestrictionsBackportCallback` | Wrapper class for {IUnusedAppRestrictionsBackportCallback}. |
| `https://developer.android.com/reference/kotlin/androidx/core/content/UnusedAppRestrictionsBackportService` | Wrapper class for . |
| `https://developer.android.com/reference/kotlin/androidx/core/content/UnusedAppRestrictionsConstants` | Shared constants related to Unused App Restrictions (e.g. Permission Revocation, App Hibernation). |
| `https://developer.android.com/reference/kotlin/androidx/core/content/UriMatcherCompat` | Helper for accessing `https://developer.android.com/reference/android/content/UriMatcher.html` to create Uri Predicate. |

## Top-level functions summary

|---|---|
| `https://developer.android.com/reference/android/content/ContentValues.html` | `https://developer.android.com/reference/kotlin/androidx/core/content/package-summary#contentValuesOf(kotlin.Array)(vararg pairs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-pair/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?>)` Returns a new `https://developer.android.com/reference/android/content/ContentValues.html` with the given key/value pairs as elements. |

## Extension functions summary

|---|---|
| `inline https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/android/content/SharedPreferences.html.https://developer.android.com/reference/kotlin/androidx/core/content/package-summary#(android.content.SharedPreferences).edit(kotlin.Boolean,kotlin.Function1)(commit: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html, action: https://developer.android.com/reference/android/content/SharedPreferences.Editor.html.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)` Allows editing of this preference instance with a call to `https://developer.android.com/reference/android/content/SharedPreferences.Editor.html#apply()` or `https://developer.android.com/reference/android/content/SharedPreferences.Editor.html#commit()` to persist the changes. |
| `inline T?` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/android/content/Context.html.https://developer.android.com/reference/kotlin/androidx/core/content/package-summary#(android.content.Context).getSystemService()()` Return the handle to a system-level service by class. |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-nothing/index.html` | `https://developer.android.com/reference/android/content/Context.html.https://developer.android.com/reference/kotlin/androidx/core/content/package-summary#(android.content.Context).receiveBroadcasts(android.content.IntentFilter,kotlin.Int,kotlin.String,android.os.Handler,kotlin.Function2)( filter: https://developer.android.com/reference/android/content/IntentFilter.html, flags: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, broadcastPermission: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?, scheduler: https://developer.android.com/reference/android/os/Handler.html?, onReceive: https://developer.android.com/reference/android/content/BroadcastReceiver.html.(https://developer.android.com/reference/android/content/Intent.html?) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` Registers a `https://developer.android.com/reference/android/content/BroadcastReceiver.html` until the coroutine is cancelled. |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-nothing/index.html` | `https://developer.android.com/reference/android/content/Context.html.https://developer.android.com/reference/kotlin/androidx/core/content/package-summary#(android.content.Context).receiveBroadcastsAsync(android.content.IntentFilter,kotlin.Int,kotlin.String,android.os.Handler,kotlin.coroutines.SuspendFunction2)( filter: https://developer.android.com/reference/android/content/IntentFilter.html, flags: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, broadcastPermission: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?, scheduler: https://developer.android.com/reference/android/os/Handler.html?, onReceive: suspend https://developer.android.com/reference/android/content/BroadcastReceiver.PendingResult.html.(https://developer.android.com/reference/android/content/Intent.html?) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` Register a `https://developer.android.com/reference/android/content/BroadcastReceiver.html` until the coroutine is cancelled. |
| `inline https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/android/content/Context.html.https://developer.android.com/reference/kotlin/androidx/core/content/package-summary#(android.content.Context).withStyledAttributes(kotlin.Int,kotlin.IntArray,kotlin.Function1)( resourceId: @https://developer.android.com/reference/kotlin/androidx/annotation/StyleRes https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, attrs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int-array/index.html, block: https://developer.android.com/reference/android/content/res/TypedArray.html.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` Executes `https://developer.android.com/reference/kotlin/androidx/core/content/package-summary#(android.content.Context).withStyledAttributes(kotlin.Int,kotlin.IntArray,kotlin.Function1)` on a `https://developer.android.com/reference/android/content/res/TypedArray.html` receiver. |
| `inline https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/android/content/Context.html.https://developer.android.com/reference/kotlin/androidx/core/content/package-summary#(android.content.Context).withStyledAttributes(android.util.AttributeSet,kotlin.IntArray,kotlin.Int,kotlin.Int,kotlin.Function1)( set: https://developer.android.com/reference/android/util/AttributeSet.html?, attrs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int-array/index.html, defStyleAttr: @https://developer.android.com/reference/kotlin/androidx/annotation/AttrRes https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, defStyleRes: @https://developer.android.com/reference/kotlin/androidx/annotation/StyleRes https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, block: https://developer.android.com/reference/android/content/res/TypedArray.html.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` Executes `https://developer.android.com/reference/kotlin/androidx/core/content/package-summary#(android.content.Context).withStyledAttributes(android.util.AttributeSet,kotlin.IntArray,kotlin.Int,kotlin.Int,kotlin.Function1)` on a `https://developer.android.com/reference/android/content/res/TypedArray.html` receiver. |

## Top-level functions

### contentValuesOf

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/content/ContentValues.kt+function:contentValuesOf)

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

Returns a new `https://developer.android.com/reference/android/content/ContentValues.html` with the given key/value pairs as elements.

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | When a value is not a supported type of `https://developer.android.com/reference/android/content/ContentValues.html`. |

## Extension functions

### SharedPreferences.edit

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/content/SharedPreferences.kt+function:edit) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

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

Allows editing of this preference instance with a call to `https://developer.android.com/reference/android/content/SharedPreferences.Editor.html#apply()` or `https://developer.android.com/reference/android/content/SharedPreferences.Editor.html#commit()` to persist the changes. Default behaviour is `https://developer.android.com/reference/android/content/SharedPreferences.Editor.html#apply()`.

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

To `https://developer.android.com/reference/android/content/SharedPreferences.Editor.html#commit()` changes:

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

### Context.getSystemService

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/content/Context.kt+function:getSystemService)

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

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

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat#getSystemService(android.content.Context,java.lang.Class<T>)` |   |

### Context.receiveBroadcasts

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/content/Context.kt+function:receiveBroadcasts)

```
suspend fun Context.receiveBroadcasts(
    filter: IntentFilter,
    flags: Int,
    broadcastPermission: String? = null,
    scheduler: Handler? = null,
    onReceive: BroadcastReceiver.(Intent?) -> Unit
): Nothing
```

Registers a `https://developer.android.com/reference/android/content/BroadcastReceiver.html` until the coroutine is cancelled.

Equivalent to calling `https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat#registerReceiver(android.content.Context,android.content.BroadcastReceiver,android.content.IntentFilter,int)`, and when the coroutine is cancelled calling `https://developer.android.com/reference/android/content/Context.html#unregisterReceiver(android.content.BroadcastReceiver)`, but exceptions from `https://developer.android.com/reference/kotlin/androidx/core/content/package-summary#(android.content.Context).receiveBroadcasts(android.content.IntentFilter,kotlin.Int,kotlin.String,android.os.Handler,kotlin.Function2)` will propagate to the caller (unregistering the receiver in the process).

The rules of `https://developer.android.com/reference/android/content/BroadcastReceiver.html#onReceive(android.content.Context, android.content.Intent)` apply here. You can use the receiver `https://developer.android.com/reference/android/content/BroadcastReceiver.html` to view/modify the current result values.

`https://developer.android.com/reference/kotlin/androidx/core/content/package-summary#(android.content.Context).receiveBroadcasts(android.content.IntentFilter,kotlin.Int,kotlin.String,android.os.Handler,kotlin.Function2)` runs on the provided `https://developer.android.com/reference/kotlin/androidx/core/content/package-summary#(android.content.Context).receiveBroadcasts(android.content.IntentFilter,kotlin.Int,kotlin.String,android.os.Handler,kotlin.Function2)` thread, or the main thread if it's null. This means it can continue running even after `https://developer.android.com/reference/kotlin/androidx/core/content/package-summary#(android.content.Context).receiveBroadcasts(android.content.IntentFilter,kotlin.Int,kotlin.String,android.os.Handler,kotlin.Function2)` is cancelled. To propagate cancellation, consider using `https://developer.android.com/reference/kotlin/androidx/core/content/package-summary#(android.content.Context).receiveBroadcastsAsync(android.content.IntentFilter,kotlin.Int,kotlin.String,android.os.Handler,kotlin.coroutines.SuspendFunction2)`.

If you wish to process broadcasts asynchronously (and concurrently), consider using `https://developer.android.com/reference/kotlin/androidx/core/content/package-summary#(android.content.Context).receiveBroadcastsAsync(android.content.IntentFilter,kotlin.Int,kotlin.String,android.os.Handler,kotlin.coroutines.SuspendFunction2)`, or manually use `https://developer.android.com/reference/android/content/BroadcastReceiver.html#goAsync()`.

Example usage:

```kotlin
import android.app.Activity.RESULT_OK
import android.content.Intent
import android.content.IntentFilter
import androidx.core.content.ContextCompat
import androidx.core.content.receiveBroadcasts
import kotlinx.coroutines.coroutineScope

coroutineScope {
  val job = launch {
    context.receiveBroadcasts(
      filter = IntentFilter(Intent.ACTION_TIME_CHANGED),
      flags = ContextCompat.RECEIVER_EXPORTED,
    ) { intent: Intent? ->
      // Process intent
      setResultCode(RESULT_OK) // Set broadcast result
    }
  }
  ...
  job.cancel() // Unregister
}
```

| Parameters |
|---|---|
| `filter: https://developer.android.com/reference/android/content/IntentFilter.html` | Selects the Intent broadcasts to be received. |
| `flags: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | If this receiver is listening for broadcasts sent from other apps - even other apps that you own - use the `https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat#RECEIVER_EXPORTED()` flag. If instead this receiver is listening only for broadcasts sent by your app, or from the system UID, use the `https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat#RECEIVER_NOT_EXPORTED()` flag. |
| `broadcastPermission: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html? = null` | String naming a permission that a broadcaster must hold in order to send and Intent to you. If null, no permission is required. |
| `scheduler: https://developer.android.com/reference/android/os/Handler.html? = null` | Handler identifying the thread will receive the Intent. If null, the main thread of the process will be used. |
| `onReceive: https://developer.android.com/reference/android/content/BroadcastReceiver.html.(https://developer.android.com/reference/android/content/Intent.html?) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | The callback equivalent of `https://developer.android.com/reference/android/content/BroadcastReceiver.html#onReceive(android.content.Context, android.content.Intent)`, taking the `https://developer.android.com/reference/android/content/BroadcastReceiver.html` as a receiver. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat#registerReceiver(android.content.Context,android.content.BroadcastReceiver,android.content.IntentFilter,int)` |   |
| `https://developer.android.com/reference/android/content/BroadcastReceiver.html#onReceive(android.content.Context, android.content.Intent)` |   |

### Context.receiveBroadcastsAsync

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/content/Context.kt+function:receiveBroadcastsAsync)

```
suspend fun Context.receiveBroadcastsAsync(
    filter: IntentFilter,
    flags: Int,
    broadcastPermission: String? = null,
    scheduler: Handler? = null,
    onReceive: suspend BroadcastReceiver.PendingResult.(Intent?) -> Unit
): Nothing
```

Register a `https://developer.android.com/reference/android/content/BroadcastReceiver.html` until the coroutine is cancelled.

Equivalent to calling `https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat#registerReceiver(android.content.Context,android.content.BroadcastReceiver,android.content.IntentFilter,int)`, and when the coroutine is cancelled calling `https://developer.android.com/reference/android/content/Context.html#unregisterReceiver(android.content.BroadcastReceiver)`, but uses `https://developer.android.com/reference/android/content/BroadcastReceiver.html#goAsync()` to allow suspending `https://developer.android.com/reference/kotlin/androidx/core/content/package-summary#(android.content.Context).receiveBroadcastsAsync(android.content.IntentFilter,kotlin.Int,kotlin.String,android.os.Handler,kotlin.coroutines.SuspendFunction2)` and calls `https://developer.android.com/reference/android/content/BroadcastReceiver.PendingResult.html#finish()` when `https://developer.android.com/reference/kotlin/androidx/core/content/package-summary#(android.content.Context).receiveBroadcastsAsync(android.content.IntentFilter,kotlin.Int,kotlin.String,android.os.Handler,kotlin.coroutines.SuspendFunction2)` returns or throws.

The rules of `https://developer.android.com/reference/android/content/BroadcastReceiver.html#goAsync()` apply here. You can use the receiver `https://developer.android.com/reference/android/content/BroadcastReceiver.PendingResult.html` to view/modify the current result values. If you wish to use the `https://developer.android.com/reference/android/content/BroadcastReceiver.html`, consider using `https://developer.android.com/reference/kotlin/androidx/core/content/package-summary#(android.content.Context).receiveBroadcasts(android.content.IntentFilter,kotlin.Int,kotlin.String,android.os.Handler,kotlin.Function2)`.

Each `https://developer.android.com/reference/kotlin/androidx/core/content/package-summary#(android.content.Context).receiveBroadcastsAsync(android.content.IntentFilter,kotlin.Int,kotlin.String,android.os.Handler,kotlin.coroutines.SuspendFunction2)` is invoked concurrently in a child coroutine of the current context, and is cancelled when `https://developer.android.com/reference/kotlin/androidx/core/content/package-summary#(android.content.Context).receiveBroadcastsAsync(android.content.IntentFilter,kotlin.Int,kotlin.String,android.os.Handler,kotlin.coroutines.SuspendFunction2)` is cancelled. If any `https://developer.android.com/reference/kotlin/androidx/core/content/package-summary#(android.content.Context).receiveBroadcastsAsync(android.content.IntentFilter,kotlin.Int,kotlin.String,android.os.Handler,kotlin.coroutines.SuspendFunction2)` throws, all other concurrent invocations are cancelled and the exception is propagated to the caller (unregistering the receiver in the process).

**Do not call `https://developer.android.com/reference/android/content/BroadcastReceiver.PendingResult.html#finish()` yourself, this is done for you when `https://developer.android.com/reference/kotlin/androidx/core/content/package-summary#(android.content.Context).receiveBroadcastsAsync(android.content.IntentFilter,kotlin.Int,kotlin.String,android.os.Handler,kotlin.coroutines.SuspendFunction2)` returns or throws.**

Example usage:

```kotlin
import android.app.Activity.RESULT_OK
import android.content.Intent
import android.content.IntentFilter
import androidx.core.content.ContextCompat
import androidx.core.content.receiveBroadcasts
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.delay

coroutineScope {
  val job = launch {
    context.receiveBroadcastsAsync(
      filter = IntentFilter(Intent.ACTION_TIME_CHANGED),
      flags = ContextCompat.RECEIVER_EXPORTED,
    ) { intent: Intent? ->
      delay(100) // Process intent with suspending work
      setResultCode(RESULT_OK) // Set broadcast result
    }
  }
  ...
  job.cancel() // Unregister and cancel ongoing callbacks.
}
```

| Parameters |
|---|---|
| `filter: https://developer.android.com/reference/android/content/IntentFilter.html` | Selects the Intent broadcasts to be received. |
| `flags: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | If this receiver is listening for broadcasts sent from other apps - even other apps that you own - use the `https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat#RECEIVER_EXPORTED()` flag. If instead this receiver is listening only for broadcasts sent by your app, or from the system UID, use the `https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat#RECEIVER_NOT_EXPORTED()` flag. |
| `broadcastPermission: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html? = null` | String naming a permission that a broadcaster must hold in order to send and Intent to you. If null, no permission is required. |
| `scheduler: https://developer.android.com/reference/android/os/Handler.html? = null` | Handler identifying the thread will receive the Intent. If null, the main thread of the process will be used. Note that this is not used to run `https://developer.android.com/reference/kotlin/androidx/core/content/package-summary#(android.content.Context).receiveBroadcastsAsync(android.content.IntentFilter,kotlin.Int,kotlin.String,android.os.Handler,kotlin.coroutines.SuspendFunction2)`, but if the handler is blocked `https://developer.android.com/reference/kotlin/androidx/core/content/package-summary#(android.content.Context).receiveBroadcastsAsync(android.content.IntentFilter,kotlin.Int,kotlin.String,android.os.Handler,kotlin.coroutines.SuspendFunction2)` will not execute. |
| `onReceive: suspend https://developer.android.com/reference/android/content/BroadcastReceiver.PendingResult.html.(https://developer.android.com/reference/android/content/Intent.html?) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | The callback equivalent of `https://developer.android.com/reference/android/content/BroadcastReceiver.html#onReceive(android.content.Context, android.content.Intent)`, taking the `https://developer.android.com/reference/android/content/BroadcastReceiver.PendingResult.html` as receiver. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/core/content/ContextCompat#registerReceiver(android.content.Context,android.content.BroadcastReceiver,android.content.IntentFilter,int)` |   |
| `https://developer.android.com/reference/android/content/BroadcastReceiver.html#onReceive(android.content.Context, android.content.Intent)` |   |

### Context.withStyledAttributes

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/content/Context.kt+function:withStyledAttributes) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

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

Executes `https://developer.android.com/reference/kotlin/androidx/core/content/package-summary#(android.content.Context).withStyledAttributes(kotlin.Int,kotlin.IntArray,kotlin.Function1)` on a `https://developer.android.com/reference/android/content/res/TypedArray.html` receiver. The `https://developer.android.com/reference/android/content/res/TypedArray.html` holds the values defined by the style resource `https://developer.android.com/reference/kotlin/androidx/core/content/package-summary#(android.content.Context).withStyledAttributes(kotlin.Int,kotlin.IntArray,kotlin.Function1)` which are listed in `https://developer.android.com/reference/kotlin/androidx/core/content/package-summary#(android.content.Context).withStyledAttributes(kotlin.Int,kotlin.IntArray,kotlin.Function1)`.

| Parameters |
|---|---|
| `resourceId: @https://developer.android.com/reference/kotlin/androidx/annotation/StyleRes https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The desired style resource. |
| `attrs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int-array/index.html` | The desired attributes. These attribute IDs must be sorted in ascending order. |
| `block: https://developer.android.com/reference/android/content/res/TypedArray.html.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | The block that will be executed. |

| See also |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html#obtainStyledAttributes(android.util.AttributeSet, int[])` |   |
| `https://developer.android.com/reference/android/content/res/Resources.Theme.html#obtainStyledAttributes(android.util.AttributeSet, int[], int, int)` |   |

### Context.withStyledAttributes

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/content/Context.kt+function:withStyledAttributes) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

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

Executes `https://developer.android.com/reference/kotlin/androidx/core/content/package-summary#(android.content.Context).withStyledAttributes(android.util.AttributeSet,kotlin.IntArray,kotlin.Int,kotlin.Int,kotlin.Function1)` on a `https://developer.android.com/reference/android/content/res/TypedArray.html` receiver. The `https://developer.android.com/reference/android/content/res/TypedArray.html` holds the attribute values in `https://developer.android.com/reference/kotlin/androidx/core/content/package-summary#(android.content.Context).withStyledAttributes(android.util.AttributeSet,kotlin.IntArray,kotlin.Int,kotlin.Int,kotlin.Function1)` that are listed in `https://developer.android.com/reference/kotlin/androidx/core/content/package-summary#(android.content.Context).withStyledAttributes(android.util.AttributeSet,kotlin.IntArray,kotlin.Int,kotlin.Int,kotlin.Function1)`. In addition, if the given `https://developer.android.com/reference/android/util/AttributeSet.html` specifies a style class (through the `style` attribute), that style will be applied on top of the base attributes it defines.

| Parameters |
|---|---|
| `set: https://developer.android.com/reference/android/util/AttributeSet.html? = null` | The base set of attribute values. |
| `attrs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int-array/index.html` | The desired attributes to be retrieved. These attribute IDs must be sorted in ascending order. |
| `defStyleAttr: @https://developer.android.com/reference/kotlin/androidx/annotation/AttrRes https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = 0` | An attribute in the current theme that contains a reference to a style resource that supplies defaults values for the `https://developer.android.com/reference/android/content/res/TypedArray.html`. Can be 0 to not look for defaults. |
| `defStyleRes: @https://developer.android.com/reference/kotlin/androidx/annotation/StyleRes https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = 0` | A resource identifier of a style resource that supplies default values for the `https://developer.android.com/reference/android/content/res/TypedArray.html`, used only if `https://developer.android.com/reference/kotlin/androidx/core/content/package-summary#(android.content.Context).withStyledAttributes(android.util.AttributeSet,kotlin.IntArray,kotlin.Int,kotlin.Int,kotlin.Function1)` is 0 or can not be found in the theme. Can be 0 to not look for defaults. |
| `block: https://developer.android.com/reference/android/content/res/TypedArray.html.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | The block that will be executed. |

| See also |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html#obtainStyledAttributes(android.util.AttributeSet, int[])` |   |
| `https://developer.android.com/reference/android/content/res/Resources.Theme.html#obtainStyledAttributes(android.util.AttributeSet, int[], int, int)` |   |