pub struct Receiver {
    pub direct_boot_aware: Option<VarOrBool>,
    pub enabled: Option<VarOrBool>,
    pub exported: Option<VarOrBool>,
    pub icon: Option<MipmapOrDrawableResource>,
    pub label: Option<StringResourceOrString>,
    pub name: String,
    pub permission: Option<String>,
    pub process: Option<String>,
    pub intent_filter: Vec<IntentFilter>,
    pub meta_data: Vec<MetaData>,
}
Expand description

Declares a broadcast receiver (a BroadcastReceiver subclass) as one of the application’s components.

Broadcast receivers enable applications to receive intents that are broadcast by the system or by other applications, even when other components of the application are not running.

There are two ways to make a broadcast receiver known to the system: One is declare it in the manifest file with this element. The other is to create the receiver dynamically in code and register it with the Context.registerReceiver() method. For more information about how to dynamically create receivers, see the BroadcastReceiver class description.

Warning

Limit how many broadcast receivers you set in your app. Having too many broadcast receivers can affect your app’s performance and the battery life of users’ devices. For more information about APIs you can use instead of the BroadcastReceiver class for scheduling background work, see Background Optimizations.

XML Syntax

<receiver android:directBootAware=["true" | "false"]
          android:enabled=["true" | "false"]
          android:exported=["true" | "false"]
          android:icon="drawable resource"
          android:label="string resource"
          android:name="string"
          android:permission="string"
          android:process="string" >
      ...
</receiver>

Contained in

Can contain

Introduced in

API Level 1

Fields§

§direct_boot_aware: Option<VarOrBool>

Whether or not the broadcast receiver is direct-boot aware; that is, whether or not it can run before the user unlocks the device.

Note

During Direct Boot, a broadcast receiver in your application can only access the data that is stored in device protected storage.

The default value is “false”.

§enabled: Option<VarOrBool>

Whether or not the broadcast receiver can be instantiated by the system — "true" if it can be, and "false" if not. The default value is "true".

The <application> element has its own enabled attribute that applies to all application components, including broadcast receivers. The <application> and attributes must both be "true" for the broadcast receiver to be enabled. If either is "false“, it is disabled; it cannot be instantiated.

§exported: Option<VarOrBool>

Whether the broadcast receiver can receive messages from non-system sources outside its application — "true" if it can, and "false" if not. If "false", the only messages the broadcast receiver can receive are those sent by the system, components of the same application, or applications with the same user ID.

If unspecified, the default value depends on whether the broadcast receiver contains intent filters. If the receiver contains at least one intent filter, then the default value is "true" Otherwise, the default value is "false".

This attribute is not the only way to limit a broadcast receiver’s external exposure. You can also use a permission to limit the external entities that can send it messages (see the permission attribute).

§icon: Option<MipmapOrDrawableResource>

An icon representing the service. This attribute must be set as a reference to a drawable resource containing the image definition. If it is not set, the icon specified for the application as a whole is used instead (see the <application> element’s icon attribute).

The service’s icon — whether set here or by the <application> element — is also the default icon for all the service’s intent filters (see the <intent-filter> element’s icon attribute).

§label: Option<StringResourceOrString>

A name for the service that can be displayed to users. If this attribute is not set, the label set for the application as a whole is used instead (see the <application> element’s label attribute).

The service’s label — whether set here or by the <application> element — is also the default label for all the service’s intent filters (see the <intent-filter> element’s label attribute).

The label should be set as a reference to a string resource, so that it can be localized like other strings in the user interface. However, as a convenience while you’re developing the application, it can also be set as a raw string.

§name: String

The name of the class that implements the broadcast receiver, a subclass of BroadcastReceiver. This should be a fully qualified class name (such as, "com.example.project.ReportReceiver"). However, as a shorthand, if the first character of the name is a period (for example, “. ReportReceiver”), it is appended to the package name specified in the <manifest> element.

Once you publish your application, you should not change this name (unless you’ve set android:exported="false").

There is no default. The name must be specified.

§permission: Option<String>

The name of a permission that broadcasters must have to send a message to the broadcast receiver. If this attribute is not set, the permission set by the <application> element’s permission attribute applies to the broadcast receiver. If neither attribute is set, the receiver is not protected by a permission.

For more information on permissions, see the Permissions section in the introduction and a separate document, Security and Permissions.

§process: Option<String>

The name of the process where the service is to run. Normally, all components of an application run in the default process created for the application. It has the same name as the application package. The <application> element’s process attribute can set a different default for all components. But component can override the default with its own process attribute, allowing you to spread your application across multiple processes.

If the name assigned to this attribute begins with a colon (':'), a new process, private to the application, is created when it’s needed and the service runs in that process. If the process name begins with a lowercase character, the service will run in a global process of that name, provided that it has permission to do so. This allows components in different applications to share a process, reducing resource usage.

§intent_filter: Vec<IntentFilter>§meta_data: Vec<MetaData>

Trait Implementations§

source§

impl Clone for Receiver

source§

fn clone(&self) -> Receiver

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Receiver

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Receiver

source§

fn default() -> Receiver

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for Receiver

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl PartialEq<Receiver> for Receiver

source§

fn eq(&self, other: &Receiver) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Receiver

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl YaDeserialize for Receiver

source§

fn deserialize<R: Read>(reader: &mut Deserializer<R>) -> Result<Self, String>

source§

impl YaSerialize for Receiver

source§

fn serialize<W: Write>(&self, writer: &mut Serializer<W>) -> Result<(), String>

source§

fn serialize_attributes( &self, source_attributes: Vec<OwnedAttribute>, source_namespace: Namespace ) -> Result<(Vec<OwnedAttribute>, Namespace), String>

source§

impl Eq for Receiver

source§

impl StructuralEq for Receiver

source§

impl StructuralPartialEq for Receiver

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,