Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Constants](https://developer.android.com/reference/android/app/BroadcastOptions#constants) \| [Methods](https://developer.android.com/reference/android/app/BroadcastOptions#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/app/BroadcastOptions#inhmethods)

# BroadcastOptions

*** ** * ** ***

` public class BroadcastOptions `   
` extends https://developer.android.com/reference/java/lang/Object ` ` `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.app.BroadcastOptions |

<br />

*** ** * ** ***

Helper class for building an options Bundle that can be used with `https://developer.android.com/reference/android/content/Context#sendBroadcast(android.content.Intent)` and related methods.

## Summary

| ### Constants ||
|---|---|
| `int` | `https://developer.android.com/reference/android/app/BroadcastOptions#DEFERRAL_POLICY_DEFAULT` Deferral policy that indicates no desire has been expressed, and that the system should use a reasonable default behavior. |
| `int` | `https://developer.android.com/reference/android/app/BroadcastOptions#DEFERRAL_POLICY_NONE` Deferral policy that indicates a strong desire that no receiver of this broadcast should be deferred. |
| `int` | `https://developer.android.com/reference/android/app/BroadcastOptions#DEFERRAL_POLICY_UNTIL_ACTIVE` Deferral policy that indicates a strong desire that each receiver of this broadcast should be deferred until that receiver's process is in an active (non-cached) state. |
| `int` | `https://developer.android.com/reference/android/app/BroadcastOptions#DELIVERY_GROUP_POLICY_ALL` Delivery group policy that indicates that all the broadcasts in the delivery group need to be delivered as is. |
| `int` | `https://developer.android.com/reference/android/app/BroadcastOptions#DELIVERY_GROUP_POLICY_MOST_RECENT` Delivery group policy that indicates that only the most recent broadcast in the delivery group need to be delivered and the rest can be dropped. |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/app/BroadcastOptions#clearDeferralPolicy()() ` Clears any deferral policy for this broadcast that specifies how this broadcast can be deferred for delivery at some future point. |
| ` void` | ` https://developer.android.com/reference/android/app/BroadcastOptions#clearDeliveryGroupMatchingKey()() ` Clears the namespace and key that was previously set using `https://developer.android.com/reference/android/app/BroadcastOptions#setDeliveryGroupMatchingKey(java.lang.String,%20java.lang.String)`. |
| ` void` | ` https://developer.android.com/reference/android/app/BroadcastOptions#clearDeliveryGroupPolicy()() ` Clears any previously set delivery group policies using `https://developer.android.com/reference/android/app/BroadcastOptions#setDeliveryGroupMatchingKey(java.lang.String,%20java.lang.String)` and resets the delivery group policy to the default value (`https://developer.android.com/reference/android/app/BroadcastOptions#DELIVERY_GROUP_POLICY_ALL`). |
| ` static https://developer.android.com/reference/android/app/BroadcastOptions` | ` https://developer.android.com/reference/android/app/BroadcastOptions#fromBundle(android.os.Bundle)(https://developer.android.com/reference/android/os/Bundle options) ` Returns a `https://developer.android.com/reference/android/app/BroadcastOptions` parsed from the given `https://developer.android.com/reference/android/os/Bundle`, typically generated from `https://developer.android.com/reference/android/app/BroadcastOptions#toBundle()`. |
| ` int` | ` https://developer.android.com/reference/android/app/BroadcastOptions#getDeferralPolicy()() ` Gets deferral policy for this broadcast that specifies how this broadcast can be deferred for delivery at some future point. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/app/BroadcastOptions#getDeliveryGroupMatchingKey()() ` Return the namespace and key that is used to identify the delivery group that this broadcast belongs to. |
| ` int` | ` https://developer.android.com/reference/android/app/BroadcastOptions#getDeliveryGroupPolicy()() ` Get the delivery group policy for this broadcast that specifies how multiple broadcasts belonging to the same delivery group has to be handled. |
| ` boolean` | ` https://developer.android.com/reference/android/app/BroadcastOptions#isShareIdentityEnabled()() ` Returns whether the broadcasting app has opted-in to sharing its identity with the receiver. |
| ` static https://developer.android.com/reference/android/app/BroadcastOptions` | ` https://developer.android.com/reference/android/app/BroadcastOptions#makeBasic()() ` Creates a basic `https://developer.android.com/reference/android/app/BroadcastOptions` with no options initially set. |
| ` https://developer.android.com/reference/android/app/BroadcastOptions` | ` https://developer.android.com/reference/android/app/BroadcastOptions#setDeferralPolicy(int)(int deferralPolicy) ` Sets deferral policy for this broadcast that specifies how this broadcast can be deferred for delivery at some future point. |
| ` https://developer.android.com/reference/android/app/BroadcastOptions` | ` https://developer.android.com/reference/android/app/BroadcastOptions#setDeliveryGroupMatchingKey(java.lang.String,%20java.lang.String)(https://developer.android.com/reference/java/lang/String namespace, https://developer.android.com/reference/java/lang/String key) ` Set namespace and key to identify the delivery group that this broadcast belongs to. |
| ` https://developer.android.com/reference/android/app/BroadcastOptions` | ` https://developer.android.com/reference/android/app/BroadcastOptions#setDeliveryGroupPolicy(int)(int policy) ` Set delivery group policy for this broadcast to specify how multiple broadcasts belonging to the same delivery group has to be handled. |
| ` https://developer.android.com/reference/android/app/BroadcastOptions` | ` https://developer.android.com/reference/android/app/BroadcastOptions#setShareIdentityEnabled(boolean)(boolean shareIdentityEnabled) ` Sets whether the identity of the broadcasting app should be shared with all receivers that will receive this broadcast. |
| ` https://developer.android.com/reference/android/os/Bundle` | ` https://developer.android.com/reference/android/app/BroadcastOptions#toBundle()() ` Returns the created options as a Bundle, which can be passed to `https://developer.android.com/reference/android/content/Context#sendBroadcast(android.content.Intent)` and related methods. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.

## Constants

### DEFERRAL_POLICY_DEFAULT

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int DEFERRAL_POLICY_DEFAULT
```

Deferral policy that indicates no desire has been expressed, and that the system should use a reasonable default behavior.

<br />

Constant Value: 0 (0x00000000)

### DEFERRAL_POLICY_NONE

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int DEFERRAL_POLICY_NONE
```

Deferral policy that indicates a strong desire that no receiver of this broadcast should be deferred.

<br />

Constant Value: 1 (0x00000001)

### DEFERRAL_POLICY_UNTIL_ACTIVE

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int DEFERRAL_POLICY_UNTIL_ACTIVE
```

Deferral policy that indicates a strong desire that each receiver of this broadcast should be deferred until that receiver's process is in an active (non-cached) state. Whether an app's process state is considered active is independent of its standby bucket.

This policy only applies to runtime registered receivers of a broadcast, and does not apply to ordered broadcasts, alarm broadcasts, interactive broadcasts, or manifest broadcasts.

This policy means that a runtime registered receiver will not typically execute until that receiver's process is brought to an active state by some other action, such as a job, alarm, or service binding. As a result, the receiver may be delayed indefinitely.

When this policy is set on an unordered broadcast with a completion callback, the completion callback will run once all eligible processes have finished receiving the broadcast. Processes in inactive process state are not considered eligible and may not receive the broadcast prior to the completion callback.

<br />

Constant Value: 2 (0x00000002)

### DELIVERY_GROUP_POLICY_ALL

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int DELIVERY_GROUP_POLICY_ALL
```

Delivery group policy that indicates that all the broadcasts in the delivery group need to be delivered as is.

<br />

Constant Value: 0 (0x00000000)

### DELIVERY_GROUP_POLICY_MOST_RECENT

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int DELIVERY_GROUP_POLICY_MOST_RECENT
```

Delivery group policy that indicates that only the most recent broadcast in the delivery group need to be delivered and the rest can be dropped.

<br />

Constant Value: 1 (0x00000001)

## Public methods

### clearDeferralPolicy

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void clearDeferralPolicy ()
```

Clears any deferral policy for this broadcast that specifies how this broadcast can be deferred for delivery at some future point.

<br />

### clearDeliveryGroupMatchingKey

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void clearDeliveryGroupMatchingKey ()
```

Clears the namespace and key that was previously set using `https://developer.android.com/reference/android/app/BroadcastOptions#setDeliveryGroupMatchingKey(java.lang.String,%20java.lang.String)`.

<br />

### clearDeliveryGroupPolicy

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void clearDeliveryGroupPolicy ()
```

Clears any previously set delivery group policies using `https://developer.android.com/reference/android/app/BroadcastOptions#setDeliveryGroupMatchingKey(java.lang.String,%20java.lang.String)` and resets the delivery group policy to the default value (`https://developer.android.com/reference/android/app/BroadcastOptions#DELIVERY_GROUP_POLICY_ALL`).

<br />

### fromBundle

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static BroadcastOptions fromBundle (Bundle options)
```

Returns a `https://developer.android.com/reference/android/app/BroadcastOptions` parsed from the given `https://developer.android.com/reference/android/os/Bundle`, typically generated from `https://developer.android.com/reference/android/app/BroadcastOptions#toBundle()`.

<br />

| Parameters ||
|---|---|
| `options` | `Bundle`: This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/app/BroadcastOptions` | This value cannot be `null`. <br /> |

### getDeferralPolicy

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int getDeferralPolicy ()
```

Gets deferral policy for this broadcast that specifies how this broadcast can be deferred for delivery at some future point.

<br />

| Returns ||
|---|---|
| `int` | Value is one of the following: - `https://developer.android.com/reference/android/app/BroadcastOptions#DEFERRAL_POLICY_DEFAULT` - `https://developer.android.com/reference/android/app/BroadcastOptions#DEFERRAL_POLICY_NONE` - `https://developer.android.com/reference/android/app/BroadcastOptions#DEFERRAL_POLICY_UNTIL_ACTIVE` |

### getDeliveryGroupMatchingKey

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String getDeliveryGroupMatchingKey ()
```

Return the namespace and key that is used to identify the delivery group that this broadcast belongs to.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | the delivery group namespace and key that was previously set using `https://developer.android.com/reference/android/app/BroadcastOptions#setDeliveryGroupMatchingKey(java.lang.String,%20java.lang.String)`, concatenated with a `:`. This value may be `null`. <br /> |

### getDeliveryGroupPolicy

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int getDeliveryGroupPolicy ()
```

Get the delivery group policy for this broadcast that specifies how multiple broadcasts belonging to the same delivery group has to be handled.

<br />

| Returns ||
|---|---|
| `int` | Value is one of the following: - `https://developer.android.com/reference/android/app/BroadcastOptions#DELIVERY_GROUP_POLICY_ALL` - `https://developer.android.com/reference/android/app/BroadcastOptions#DELIVERY_GROUP_POLICY_MOST_RECENT` |

### isShareIdentityEnabled

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean isShareIdentityEnabled ()
```

Returns whether the broadcasting app has opted-in to sharing its identity with the receiver.

<br />

| Returns ||
|---|---|
| `boolean` | `true` if the broadcasting app has opted in to sharing its identity <br /> |

**See also:**

- `https://developer.android.com/reference/android/app/BroadcastOptions#setShareIdentityEnabled(boolean)`
- `https://developer.android.com/reference/android/content/BroadcastReceiver#getSentFromUid()`
- `https://developer.android.com/reference/android/content/BroadcastReceiver#getSentFromPackage()`

### makeBasic

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static BroadcastOptions makeBasic ()
```

Creates a basic `https://developer.android.com/reference/android/app/BroadcastOptions` with no options initially set.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/app/BroadcastOptions` | an instance of `BroadcastOptions` against which options can be set. This value cannot be `null`. <br /> |

### setDeferralPolicy

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public BroadcastOptions setDeferralPolicy (int deferralPolicy)
```

Sets deferral policy for this broadcast that specifies how this broadcast can be deferred for delivery at some future point.

<br />

| Parameters ||
|---|---|
| `deferralPolicy` | `int`: Value is one of the following: - `https://developer.android.com/reference/android/app/BroadcastOptions#DEFERRAL_POLICY_DEFAULT` - `https://developer.android.com/reference/android/app/BroadcastOptions#DEFERRAL_POLICY_NONE` - `https://developer.android.com/reference/android/app/BroadcastOptions#DEFERRAL_POLICY_UNTIL_ACTIVE` |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/app/BroadcastOptions` | This value cannot be `null`. <br /> |

### setDeliveryGroupMatchingKey

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public BroadcastOptions setDeliveryGroupMatchingKey (String namespace, 
                String key)
```

Set namespace and key to identify the delivery group that this broadcast belongs to.

If `namespace` and `key` are specified, then another broadcast will be considered to be in the same delivery group as this iff it has the same `namespace` and `key`.

If not matching key using this API then by default `https://developer.android.com/reference/android/content/Intent#filterEquals(android.content.Intent)` will be used to identify the delivery group.

<br />

| Parameters ||
|---|---|
| `namespace` | `String`: This value cannot be `null`. <br /> |
| `key` | `String`: This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/app/BroadcastOptions` | This value cannot be `null`. <br /> |

### setDeliveryGroupPolicy

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public BroadcastOptions setDeliveryGroupPolicy (int policy)
```

Set delivery group policy for this broadcast to specify how multiple broadcasts belonging to the same delivery group has to be handled.

<br />

| Parameters ||
|---|---|
| `policy` | `int`: Value is one of the following: - `https://developer.android.com/reference/android/app/BroadcastOptions#DELIVERY_GROUP_POLICY_ALL` - `https://developer.android.com/reference/android/app/BroadcastOptions#DELIVERY_GROUP_POLICY_MOST_RECENT` |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/app/BroadcastOptions` | This value cannot be `null`. <br /> |

### setShareIdentityEnabled

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public BroadcastOptions setShareIdentityEnabled (boolean shareIdentityEnabled)
```

Sets whether the identity of the broadcasting app should be shared with all receivers that will receive this broadcast.

Use this option when broadcasting to a receiver that needs to know the identity of the broadcaster; with this set to `true`, the receiver will have access to the broadcasting app's package name and uid.

Defaults to `false` if not set.

<br />

| Parameters ||
|---|---|
| `shareIdentityEnabled` | `boolean`: whether the broadcasting app's identity should be shared with the receiver <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/app/BroadcastOptions` | `this` `https://developer.android.com/reference/android/app/BroadcastOptions` instance. This value cannot be `null`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/content/BroadcastReceiver#getSentFromUid()`
- `https://developer.android.com/reference/android/content/BroadcastReceiver#getSentFromPackage()`

### toBundle

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Bundle toBundle ()
```

Returns the created options as a Bundle, which can be passed to `https://developer.android.com/reference/android/content/Context#sendBroadcast(android.content.Intent)` and related methods. Note that the returned Bundle is still owned by the BroadcastOptions object; you must not modify it, but can supply it to the sendBroadcast methods that take an options Bundle.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/Bundle` | This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException` | if the broadcast option values are inconsistent. For example, if the delivery group policy is specified as "MERGED" but no extras merger is supplied. |