BroadcastOptions
public
class
BroadcastOptions
extends Object
java.lang.Object | |
↳ | android.app.BroadcastOptions |
Helper class for building an options Bundle that can be used with
Context.sendBroadcast(Intent)
and related methods.
Summary
Constants | |
---|---|
int |
DEFERRAL_POLICY_DEFAULT
Deferral policy that indicates no desire has been expressed, and that the system should use a reasonable default behavior. |
int |
DEFERRAL_POLICY_NONE
Deferral policy that indicates a strong desire that no receiver of this broadcast should be deferred. |
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. |
int |
DELIVERY_GROUP_POLICY_ALL
Delivery group policy that indicates that all the broadcasts in the delivery group need to be delivered as is. |
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. |
Public methods | |
---|---|
void
|
clearDeferralPolicy()
Clears any deferral policy for this broadcast that specifies how this broadcast can be deferred for delivery at some future point. |
void
|
clearDeliveryGroupMatchingKey()
Clears the namespace and key that was previously set using
|
void
|
clearDeliveryGroupPolicy()
Clears any previously set delivery group policies using
|
static
BroadcastOptions
|
fromBundle(Bundle options)
Returns a |
int
|
getDeferralPolicy()
Gets deferral policy for this broadcast that specifies how this broadcast can be deferred for delivery at some future point. |
String
|
getDeliveryGroupMatchingKey()
Return the namespace and key that is used to identify the delivery group that this broadcast belongs to. |
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. |
boolean
|
isShareIdentityEnabled()
Returns whether the broadcasting app has opted-in to sharing its identity with the receiver. |
static
BroadcastOptions
|
makeBasic()
Creates a basic |
BroadcastOptions
|
setDeferralPolicy(int deferralPolicy)
Sets deferral policy for this broadcast that specifies how this broadcast can be deferred for delivery at some future point. |
BroadcastOptions
|
setDeliveryGroupMatchingKey(String namespace, String key)
Set namespace and key to identify the delivery group that this broadcast belongs to. |
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. |
BroadcastOptions
|
setShareIdentityEnabled(boolean shareIdentityEnabled)
Sets whether the identity of the broadcasting app should be shared with all receivers that will receive this broadcast. |
Bundle
|
toBundle()
Returns the created options as a Bundle, which can be passed to
|
Inherited methods | |
---|---|
Constants
DEFERRAL_POLICY_DEFAULT
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.
Constant Value: 0 (0x00000000)
DEFERRAL_POLICY_NONE
public static final int DEFERRAL_POLICY_NONE
Deferral policy that indicates a strong desire that no receiver of this broadcast should be deferred.
Constant Value: 1 (0x00000001)
DEFERRAL_POLICY_UNTIL_ACTIVE
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.
Constant Value: 2 (0x00000002)
DELIVERY_GROUP_POLICY_ALL
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.
Constant Value: 0 (0x00000000)
DELIVERY_GROUP_POLICY_MOST_RECENT
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.
Constant Value: 1 (0x00000001)
Public methods
clearDeferralPolicy
public void clearDeferralPolicy ()
Clears any deferral policy for this broadcast that specifies how this broadcast can be deferred for delivery at some future point.
clearDeliveryGroupMatchingKey
public void clearDeliveryGroupMatchingKey ()
Clears the namespace and key that was previously set using
setDeliveryGroupMatchingKey(java.lang.String, java.lang.String)
.
clearDeliveryGroupPolicy
public void clearDeliveryGroupPolicy ()
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
public static BroadcastOptions fromBundle (Bundle options)
Returns a BroadcastOptions
parsed from the given Bundle
,
typically generated from toBundle()
.
Parameters | |
---|---|
options |
Bundle : This value cannot be null . |
Returns | |
---|---|
BroadcastOptions |
This value cannot be null . |
getDeferralPolicy
public int getDeferralPolicy ()
Gets deferral policy for this broadcast that specifies how this broadcast can be deferred for delivery at some future point.
Returns | |
---|---|
int |
Value is DEFERRAL_POLICY_DEFAULT , DEFERRAL_POLICY_NONE , or DEFERRAL_POLICY_UNTIL_ACTIVE |
getDeliveryGroupMatchingKey
public String getDeliveryGroupMatchingKey ()
Return the namespace and key that is used to identify the delivery group that this broadcast belongs to.
Returns | |
---|---|
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
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.
Returns | |
---|---|
int |
Value is DELIVERY_GROUP_POLICY_ALL , DELIVERY_GROUP_POLICY_MOST_RECENT , or android.app.BroadcastOptions.DELIVERY_GROUP_POLICY_MERGED |
isShareIdentityEnabled
public boolean isShareIdentityEnabled ()
Returns whether the broadcasting app has opted-in to sharing its identity with the receiver.
Returns | |
---|---|
boolean |
true if the broadcasting app has opted in to sharing its identity |
makeBasic
public static BroadcastOptions makeBasic ()
Creates a basic BroadcastOptions
with no options initially set.
Returns | |
---|---|
BroadcastOptions |
an instance of BroadcastOptions against which options can be set
This value cannot be null . |
setDeferralPolicy
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.
Parameters | |
---|---|
deferralPolicy |
int : Value is DEFERRAL_POLICY_DEFAULT , DEFERRAL_POLICY_NONE , or DEFERRAL_POLICY_UNTIL_ACTIVE |
Returns | |
---|---|
BroadcastOptions |
This value cannot be null . |
setDeliveryGroupMatchingKey
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
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 . |
Returns | |
---|---|
BroadcastOptions |
This value cannot be null . |
setDeliveryGroupPolicy
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.
Parameters | |
---|---|
policy |
int : Value is DELIVERY_GROUP_POLICY_ALL , DELIVERY_GROUP_POLICY_MOST_RECENT , or android.app.BroadcastOptions.DELIVERY_GROUP_POLICY_MERGED |
Returns | |
---|---|
BroadcastOptions |
This value cannot be null . |
setShareIdentityEnabled
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.
Parameters | |
---|---|
shareIdentityEnabled |
boolean : whether the broadcasting app's identity should be shared with the
receiver |
Returns | |
---|---|
BroadcastOptions |
this BroadcastOptions instance
This value cannot be null . |
toBundle
public Bundle toBundle ()
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.
Returns | |
---|---|
Bundle |
This value cannot be null . |
Throws | |
---|---|
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. |