# ShareTarget

Artifact: [androidx.browser:browser](https://developer.android.com/jetpack/androidx/releases/browser) [View Source](https://cs.android.com/search?q=file:androidx/browser/trusted/sharing/ShareTarget.java+class:androidx.browser.trusted.sharing.ShareTarget) Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/browser#1.2.0)

*** ** * ** ***


```
public final class ShareTarget
```

<br />

*** ** * ** ***

Describes a Web Share Target associated with a Trusted Web Activity. The structure of a ShareTarget object follows the specification \[1\] of the "share_target" object within web manifest json, with the following exceptions: - The "action" field specifies the full URL of the Share Target, and not only the path. - There is no "url" field in the "params" object, since urls are not supplied separately from text in Android's ACTION_SEND and ACTION_SEND_MULTIPLE intents. \[1\] https://wicg.github.io/web-share-target/level-2/

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget.FileFormField` Defines a form field for sharing files. |
| `public class https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget.Params` Contains parameter names to be used for the data being shared. |

| ### Constants |
|---|---|
| `static final https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget#ENCODING_TYPE_MULTIPART() = "multipart/form-data"` An encoding type to be used with POST requests (see `https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget#encodingType()`) corresponding to `multipart/form-data` of the HTTP POST standard \[1\]. |
| `static final https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget#ENCODING_TYPE_URL_ENCODED() = "application/x-www-form-urlencoded"` An encoding type to be used with POST requests (see `https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget#encodingType()`) corresponding to `application/x-www-form-urlencoded` of the HTTP POST standard \[1\]. |
| `static final https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget#KEY_ACTION() = "androidx.browser.trusted.sharing.KEY_ACTION"` Bundle key for `https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget#action()`. |
| `static final https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget#KEY_ENCTYPE() = "androidx.browser.trusted.sharing.KEY_ENCTYPE"` Bundle key for `https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget#encodingType()`. |
| `static final https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget#KEY_METHOD() = "androidx.browser.trusted.sharing.KEY_METHOD"` Bundle key for `https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget#method()`. |
| `static final https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget#KEY_PARAMS() = "androidx.browser.trusted.sharing.KEY_PARAMS"` Bundle key for `https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget#params()`. |
| `static final https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget#METHOD_GET() = "GET"` See `https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget#method()`. |
| `static final https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget#METHOD_POST() = "POST"` See `https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget#method()`. |

| ### Public fields |
|---|---|
| `final @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget#action()` URL of the Web Share Target. |
| `final @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget#encodingType()` Specifies how the shared data should be encoded in the body of a POST request. |
| `final @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget#method()` HTTP request method for the Web Share Target. |
| `final @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget.Params` | `https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget#params()` Contains the parameter names, see `https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget.Params`. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget#ShareTarget(java.lang.String,java.lang.String,java.lang.String,androidx.browser.trusted.sharing.ShareTarget.Params)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html action, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html method, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html encodingType, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget.Params params )` Creates a `https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget` with the given parameters. |

| ### Public methods |
|---|---|
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget` | `https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget#fromBundle(android.os.Bundle)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/os/Bundle.html bundle)` Unpacks the object from a `https://developer.android.com/reference/android/os/Bundle.html`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/os/Bundle.html` | `https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget#toBundle()()` Packs the object into a `https://developer.android.com/reference/android/os/Bundle.html`. |

## Constants

### ENCODING_TYPE_MULTIPART

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/browser#1.2.0)

```
public static final String ENCODING_TYPE_MULTIPART = "multipart/form-data"
```

An encoding type to be used with POST requests (see `https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget#encodingType()`) corresponding to `multipart/form-data` of the HTTP POST standard \[1\].

### ENCODING_TYPE_URL_ENCODED

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/browser#1.2.0)

```
public static final String ENCODING_TYPE_URL_ENCODED = "application/x-www-form-urlencoded"
```

An encoding type to be used with POST requests (see `https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget#encodingType()`) corresponding to `application/x-www-form-urlencoded` of the HTTP POST standard \[1\]. \[1\]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST

### KEY_ACTION

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/browser#1.2.0)

```
public static final String KEY_ACTION = "androidx.browser.trusted.sharing.KEY_ACTION"
```

Bundle key for `https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget#action()`.

### KEY_ENCTYPE

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/browser#1.2.0)

```
public static final String KEY_ENCTYPE = "androidx.browser.trusted.sharing.KEY_ENCTYPE"
```

Bundle key for `https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget#encodingType()`.

### KEY_METHOD

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/browser#1.2.0)

```
public static final String KEY_METHOD = "androidx.browser.trusted.sharing.KEY_METHOD"
```

Bundle key for `https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget#method()`.

### KEY_PARAMS

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/browser#1.2.0)

```
public static final String KEY_PARAMS = "androidx.browser.trusted.sharing.KEY_PARAMS"
```

Bundle key for `https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget#params()`.

### METHOD_GET

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/browser#1.2.0)

```
public static final String METHOD_GET = "GET"
```

See `https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget#method()`.

### METHOD_POST

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/browser#1.2.0)

```
public static final String METHOD_POST = "POST"
```

See `https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget#method()`.

## Public fields

### action

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/browser#1.2.0)

```
public final @NonNull String action
```

URL of the Web Share Target. Must belong to an origin associated with the Trusted Web Activity. For example, assuming the origin is "https://mypwa.com", the action could be "https://mypwa.com/share.html".

### encodingType

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/browser#1.2.0)

```
public final @Nullable String encodingType
```

Specifies how the shared data should be encoded in the body of a POST request. Must be `https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget#ENCODING_TYPE_MULTIPART()` or `https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget#ENCODING_TYPE_URL_ENCODED()`. Default is `https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget#ENCODING_TYPE_URL_ENCODED()`.

### method

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/browser#1.2.0)

```
public final @Nullable String method
```

HTTP request method for the Web Share Target. Must be `https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget#METHOD_GET()` or `https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget#METHOD_POST()`. Default is `https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget#METHOD_GET()`.

### params

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/browser#1.2.0)

```
public final @NonNull ShareTarget.Params params
```

Contains the parameter names, see `https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget.Params`.

## Public constructors

### ShareTarget

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/browser#1.2.0)

```
public ShareTarget(
    @NonNull String action,
    @Nullable String method,
    @Nullable String encodingType,
    @NonNull ShareTarget.Params params
)
```

Creates a `https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget` with the given parameters.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html action` | The `https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget#action()`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html method` | The `https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget#method()`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html encodingType` | The `https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget#encodingType()`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget.Params params` | The `https://developer.android.com/reference/androidx/browser/trusted/sharing/ShareTarget#params()`. |

## Public methods

### fromBundle

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/browser#1.2.0)

```
public static @Nullable ShareTarget fromBundle(@NonNull Bundle bundle)
```

Unpacks the object from a `https://developer.android.com/reference/android/os/Bundle.html`.

### toBundle

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/browser#1.2.0)

```
public @NonNull Bundle toBundle()
```

Packs the object into a `https://developer.android.com/reference/android/os/Bundle.html`.