Added in API level 34

BroadcastOptions


open class BroadcastOptions
kotlin.Any
   ↳ android.app.BroadcastOptions

Helper class for building an options Bundle that can be used with Context.sendBroadcast(Intent) and related methods.

Summary

Constants
static Int

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

static Int

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

static Int

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.

static Int

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

static Int

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
open Unit

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

open Unit

Clears the namespace and key that was previously set using setDeliveryGroupMatchingKey(java.lang.String,java.lang.String).

open Unit

Clears any previously set delivery group policies using setDeliveryGroupMatchingKey(java.lang.String,java.lang.String) and resets the delivery group policy to the default value (DELIVERY_GROUP_POLICY_ALL).

open static BroadcastOptions
fromBundle(options: Bundle)

Returns a BroadcastOptions parsed from the given Bundle, typically generated from toBundle().

open Int

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

open String?

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

open Int

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

open Boolean

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

open static BroadcastOptions

Creates a basic BroadcastOptions with no options initially set.

open BroadcastOptions
setDeferralPolicy(deferralPolicy: Int)

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

open BroadcastOptions

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

open BroadcastOptions

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

open BroadcastOptions
setShareIdentityEnabled(shareIdentityEnabled: Boolean)

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

open Bundle

Returns the created options as a Bundle, which can be passed to Context.sendBroadcast(Intent) and related methods.

Constants

DEFERRAL_POLICY_DEFAULT

Added in API level 34
static val DEFERRAL_POLICY_DEFAULT: Int

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

Value: 0

DEFERRAL_POLICY_NONE

Added in API level 34
static val DEFERRAL_POLICY_NONE: Int

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

Value: 1

DEFERRAL_POLICY_UNTIL_ACTIVE

Added in API level 34
static val DEFERRAL_POLICY_UNTIL_ACTIVE: Int

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.

Value: 2

DELIVERY_GROUP_POLICY_ALL

Added in API level 34
static val DELIVERY_GROUP_POLICY_ALL: Int

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

Value: 0

DELIVERY_GROUP_POLICY_MOST_RECENT

Added in API level 34
static val DELIVERY_GROUP_POLICY_MOST_RECENT: Int

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.

Value: 1

Public methods

clearDeferralPolicy

Added in API level 34
open fun clearDeferralPolicy(): Unit

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

clearDeliveryGroupMatchingKey

Added in API level 34
open fun clearDeliveryGroupMatchingKey(): Unit

Clears the namespace and key that was previously set using setDeliveryGroupMatchingKey(java.lang.String,java.lang.String).

clearDeliveryGroupPolicy

Added in API level 34
open fun clearDeliveryGroupPolicy(): Unit

Clears any previously set delivery group policies using setDeliveryGroupMatchingKey(java.lang.String,java.lang.String) and resets the delivery group policy to the default value (DELIVERY_GROUP_POLICY_ALL).

fromBundle

Added in API level 34
open static fun fromBundle(options: Bundle): BroadcastOptions

Returns a BroadcastOptions parsed from the given Bundle, typically generated from toBundle().

Parameters
options Bundle: This value cannot be null.
Return
BroadcastOptions This value cannot be null.

getDeferralPolicy

Added in API level 34
open fun getDeferralPolicy(): Int

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

Return
Int Value is android.app.BroadcastOptions#DEFERRAL_POLICY_DEFAULT, android.app.BroadcastOptions#DEFERRAL_POLICY_NONE, or android.app.BroadcastOptions#DEFERRAL_POLICY_UNTIL_ACTIVE

getDeliveryGroupMatchingKey

Added in API level 34
open fun getDeliveryGroupMatchingKey(): String?

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

Return
String? the delivery group namespace and key that was previously set using setDeliveryGroupMatchingKey(java.lang.String,java.lang.String), concatenated with a :. This value may be null.

getDeliveryGroupPolicy

Added in API level 34
open fun getDeliveryGroupPolicy(): Int

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

Return
Int Value is android.app.BroadcastOptions#DELIVERY_GROUP_POLICY_ALL, android.app.BroadcastOptions#DELIVERY_GROUP_POLICY_MOST_RECENT, or android.app.BroadcastOptions.DELIVERY_GROUP_POLICY_MERGED

isShareIdentityEnabled

Added in API level 34
open fun isShareIdentityEnabled(): Boolean

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

Return
Boolean true if the broadcasting app has opted in to sharing its identity

makeBasic

Added in API level 34
open static fun makeBasic(): BroadcastOptions

Creates a basic BroadcastOptions with no options initially set.

Return
BroadcastOptions an instance of BroadcastOptions against which options can be set This value cannot be null.

setDeferralPolicy

Added in API level 34
open fun setDeferralPolicy(deferralPolicy: Int): BroadcastOptions

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

Parameters
deferralPolicy Int: Value is android.app.BroadcastOptions#DEFERRAL_POLICY_DEFAULT, android.app.BroadcastOptions#DEFERRAL_POLICY_NONE, or android.app.BroadcastOptions#DEFERRAL_POLICY_UNTIL_ACTIVE
Return
BroadcastOptions This value cannot be null.

setDeliveryGroupMatchingKey

Added in API level 34
open fun setDeliveryGroupMatchingKey(
    namespace: String,
    key: String
): BroadcastOptions

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 Intent#filterEquals(Intent) will be used to identify the delivery group.

Parameters
namespace String: This value cannot be null.
key String: This value cannot be null.
Return
BroadcastOptions This value cannot be null.

setDeliveryGroupPolicy

Added in API level 34
open fun setDeliveryGroupPolicy(policy: Int): BroadcastOptions

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

Parameters
policy Int: Value is android.app.BroadcastOptions#DELIVERY_GROUP_POLICY_ALL, android.app.BroadcastOptions#DELIVERY_GROUP_POLICY_MOST_RECENT, or android.app.BroadcastOptions.DELIVERY_GROUP_POLICY_MERGED
Return
BroadcastOptions This value cannot be null.

setShareIdentityEnabled

Added in API level 34
open fun setShareIdentityEnabled(shareIdentityEnabled: Boolean): BroadcastOptions

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.

Parameters
shareIdentityEnabled Boolean: whether the broadcasting app's identity should be shared with the receiver
Return
BroadcastOptions this BroadcastOptions instance This value cannot be null.

toBundle

Added in API level 34
open fun toBundle(): Bundle

Returns the created options as a Bundle, which can be passed to Context.sendBroadcast(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.

Return
Bundle This value cannot be null.
Exceptions
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.