# AppFunctionUriValueConstraint

Artifact: [androidx.appfunctions:appfunctions](https://developer.android.com/jetpack/androidx/releases/appfunctions) [View Source](https://cs.android.com/search?q=file:androidx/appfunctions/AppFunctionUriValueConstraint.kt+class:androidx.appfunctions.AppFunctionUriValueConstraint) Added in [1.0.0-rc01](https://developer.android.com/jetpack/androidx/releases/appfunctions#1.0.0-rc01)

*** ** * ** ***


```
@Retention(value = AnnotationRetention.BINARY)
@Target(allowedTargets = [AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY])
annotation AppFunctionUriValueConstraint
```

<br />

*** ** * ** ***

Specifies constraints applied on `https://developer.android.com/reference/android/net/Uri.html` values for parameters, return types, or properties in app functions.

This annotation can be applied to:

- parameters of an `@AppFunctionDeclaration` (of type `https://developer.android.com/reference/android/net/Uri.html`),

- functions annotated with `@AppFunctionDeclaration` (for the return value of type `https://developer.android.com/reference/android/net/Uri.html`),

- or properties within an `@AppFunctionSerializable` (of type `https://developer.android.com/reference/android/net/Uri.html`).

At compile time, the compiler translates this constraint into an `https://developer.android.com/reference/kotlin/androidx/appfunctions/metadata/AppFunctionStringTypeMetadata` object with:

- `https://developer.android.com/reference/kotlin/androidx/appfunctions/metadata/AppFunctionStringTypeMetadata#format()` set to `https://developer.android.com/reference/kotlin/androidx/appfunctions/metadata/AppFunctionStringTypeMetadata#FORMAT_URI()`.

- `https://developer.android.com/reference/kotlin/androidx/appfunctions/metadata/AppFunctionStringTypeMetadata#patternMatchers()` set to one `https://developer.android.com/reference/android/os/PatternMatcher.html` per scheme in `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionUriValueConstraint#allowedSchemes()`, each matching the `"<scheme>:"` prefix with `https://developer.android.com/reference/android/os/PatternMatcher.html#PATTERN_PREFIX`.

### Usage Example:

```kotlin
// Constraining a parameter:
@AppFunctionDeclaration(isDescribedByKDoc = false)
fun updateWallpaper(
    @AppFunctionUriValueConstraint(allowedSchemes = ["content"])
    wallpaperUri: Uri
) {
    // Function body
}

// Constraining a function return value:
@AppFunctionDeclaration(isDescribedByKDoc = false)
@AppFunctionUriValueConstraint(allowedSchemes = ["content"])
fun getProfilePictureUri(): Uri {
    // Function body
}

// Constraining a property within an AppFunctionSerializable:
@AppFunctionSerializable(isDescribedByKDoc = false)
data class WallpaperConfig(
    @property:AppFunctionUriValueConstraint(allowedSchemes = ["content"])
    val wallpaperUri: Uri
)
```

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionUriValueConstraint#AppFunctionUriValueConstraint(kotlin.Array)(allowedSchemes: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html>)` |

| ### Public properties |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html>` | `https://developer.android.com/reference/kotlin/androidx/appfunctions/AppFunctionUriValueConstraint#allowedSchemes()` The list of allowed URI schemes for the annotated element defined by the developer (e.g. `["content"]` or custom schemes such as `["photo", "video"]`). |

## Public constructors

### AppFunctionUriValueConstraint

Added in [1.0.0-rc01](https://developer.android.com/jetpack/androidx/releases/appfunctions#1.0.0-rc01)

```
AppFunctionUriValueConstraint(allowedSchemes: Array<String> = [])
```

## Public properties

### allowedSchemes

```
val allowedSchemes: Array<String>
```

The list of allowed URI schemes for the annotated element defined by the developer (e.g. `["content"]` or custom schemes such as `["photo", "video"]`).

At compile time, each scheme is translated into a `https://developer.android.com/reference/android/os/PatternMatcher.html` matching the `"<scheme>:"` prefix (for example, `PatternMatcher("content:", PATTERN_PREFIX)` when `allowedSchemes = ["content"]`). If empty, any URI scheme is permitted.