Android Development-api Guide-<receiver>

Source: Internet
Author: User

<receiver>

English Original: http://developer.android.com/guide/topics/manifest/receiver-element.html
Acquisition (update) Date: 2014-7-2
Moved from the original blog: http://blog.sina.com.cn/s/blog_48d491300100zmv7.html

Grammar:
<receiverandroid: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>
Included in:
<application>
can include:
<intent-filter>
<meta-data>
Description
Declares a broadcast sink ( BroadcastReceiver subclass) and becomes a component of the application. Broadcast receivers enable applications to receive Intent that are broadcast by the system or other applications, even if the other components of the application are not running.

There are two ways to declare a broadcast sink to the system: one is declared in the Manifest file as this element, and the other is to dynamically create the sink with code and register it with the Context.registerReceiver() method. For more information about dynamically creating a broadcast sink, see BroadcastReceiver the description of the class.

Property:
android:enabled
whether the broadcast receiver can be instantiated by the system-" true " Yes, "" false cannot. The default value is " true ".

<application> Elements have their own enabled properties that apply to all components of the application, including broadcast receivers. In order to enable the broadcast sink, the <application> and <receiver> this property must be set to " true ". As long as either of these is " false ", the broadcast sink will be disabled and it will not be instantiated.

android:exported
Whether the broadcast receiver can receive messages from outside the application-" true can be received," " false does not receive. If set to false , this sink can only receive messages from components of the same program as the application or user ID.

The default value depends on whether the broadcast sink contains a Intent filter. If you do not include any filters, it means that you can only fire by specifying an Intent object of the exact class name. This means that the sink is intended for internal use only by the application (because other programs typically do not know the exact class name). The default value is " false ". On the other hand, if more than one filter is present, the broadcast sink is willing to receive Intent from the system or other applications, so the default value is " true ".

This property is not the only way to limit the extent to which a broadcast receiver is exposed to the outside. You can also use permissions to restrict external objects that can send messages (see permission properties).

android:icon
represents the icon for the broadcast receiver. This property must be set to a reference to the drawable resource that contains the definition of the picture. If this property value is not set, the global application icon will be used instead. (see <application> attributes of an element icon ).

The icon for the broadcast receiver-whether it is set in this property or in the element-is also the <application> default icon for all Intent filters in the receiver (see <intent-filter> attributes of the element icon ).

android:label
The text label of the broadcast receiver for the user to read. If this property is not set, the global Application text label is used instead (see <application> attributes of the element label ).

The text label of the broadcast receiver-whether set in this property or in the element-is also the <application> default text label for all Intent filters in the receiver (see <application> attributes of the element label ).

This label should be set as a reference to a string resource so that it can be localized like any other string in the user interface. However, it can also be set directly to a string for ease of application development.

android:name
The
name of the class that implements the broadcast sink, that is, BroadcastReceiver the subclass. This should be a fully qualified class name (such as " com.example.project.ReportReceiver "). However, if the first character is a period (for example, ""), the . ReportReceiver <manifest> package name specified by the element is automatically preceded by an abbreviation.

Once the application is published, the name should not be changed (unless it is set android:exported="false" ).

There is no default value. This name must be specified.

android:permission
The name of the permission that the sender must have to send the message to the broadcast sink. If this property is not set, the <application> permission permissions set by the element's properties are applied to the broadcast sink. If none of the above two properties are set, the sink will not be protected by a permission mechanism.

For more information about permissions, see the Permissions section of Manifest Introduction article and another document security and permissions.

android:process
the name of the process running the broadcast sink. Typically, all components of an application run in the default process at the time of creation. The name of the process is the same as the package name. <application> the attributes of an element process can set a different default process for each component. But each component can also process override the default value with its own properties, allowing the program to run across multiple processes.

If the name of this property value begins with a colon (': '), a process that is private to the program will be created if necessary, and the broadcast sink will run in the new process. If the process name starts with a lowercase letter, the broadcast sink runs in a global process named this name and gives the appropriate access rights. This allows multiple components of different applications to share the same process to reduce resource usage.

Introduced from:
API Level 1

Android Development-api Guide-<receiver>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.