【翻译】(61)receiver元素
see
http://developer.android.com/guide/topics/manifest/receiver-element.html
原文见
http://developer.android.com/guide/topics/manifest/receiver-element.html
-------------------------------
<receiver>
receiver元素
-------------------------------
* syntax:
* 语法:
-------------------------------
<receiver 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:
* 被包含在:
<application>
* can contain:
* 可以包含:
<intent-filter>
<meta-data>
* 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.
声明一个广播接收器(一个BroadcastReceiver子类)作为应用程序组件之一。广播接收器使应用程序能接收由系统或其它应用程序广播的意图,即便当应用程序的其它组件不在运行。
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. See the BroadcastReceiver class description for more on dynamically created receivers.
有两种方式使一个广播接收器让系统知道:一种方式是在清单文件中用这个元素声明它。其它方式是在代码中动态地创建接收器并且用Context.registerReceiver()方法注册它。见BroadcastReceiver类的描述以获得关于被动态创建的接收器的更多信息。
* attributes:
* 属性:
* android:enabled
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".
广播接收器是否可以被系统实例化——"true"如果它可以,而"false"如果它不可以。默认值为"true"。
The <application> element has its own enabled attribute that applies to all application components, including broadcast receivers. The <application> and <receiver> attributes must both be "true" for the broadcast receiver to be enabled. If either is "false", it is disabled; it cannot be instantiated.
<application>元素拥有它自己的enabled属性,它应用到所有应用程序组件,包括广播接收器。<application>和<receiver>属性必须都是"true"以让广播接收器被使能。如果其中一个为"false",它被屏蔽;它不能被实例化。
* android:exported
Whether or not the broadcast receiver can receive messages from 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 components of the same application or applications with the same user ID.
广播接收器是否可以从它的应用程序外部的源接收消息——"true"如果它可以,而"false"如果它不可以。如果"false",广播接收器可以接收的消息只是由相同应用程序或带有相同用户ID的应用程序的组件发出的那些消息。
The default value depends on whether the broadcast receiver contains intent filters. The absence of any filters means that it can be invoked only by Intent objects that specify its exact class name. This implies that the receiver is intended only for application-internal use (since others would not normally know the class name). So in this case, the default value is "false". On the other hand, the presence of at least one filter implies that the broadcast receiver is intended to receive intents broadcast by the system or other applications, so the default value is "true".
默认值依赖于广播接收器是否包含意图过滤器。不存在任何过滤器意味着它只可以被指定它的具体类名的Intent对象调用。这暗示接收器倾向于只给应用程序内部使用(因为其它应用程序通常不知道该类名)。所以在这种情况下,默认值为"false"。另一方面,存在至少一个过滤器暗示广播接收器倾向于接收由系统或其它应用程序广播的意图,所以默认值为"true"。
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).
这个属性并非限制一个广播接收器的对外暴露的唯一方式。你也可以使用一个权限来限制可以向它发送消息的外部实体(见permission属性)。
* android:icon
An icon representing the broadcast receiver. 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).
一个代表广播接收器的图标。这个属性必须被设置为指向包含图片定义的可绘画对象资源的引用。如果它不被设置,那么改为使用为应用程序整体指定的图标(见<application>元素的icon属性)。
The broadcast receiver's icon — whether set here or by the <application> element — is also the default icon for all the receiver's intent filters (see the <intent-filter> element's icon attribute).
广播接收器的图标——不管在这里设置还是通过<application>元素——也是用于所有接收器的意图过滤器的默认图标(见<intent-filter>元素的icon属性)。
* android:label
A user-readable label for the broadcast receiver. 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).
一个用于广播接收器的用户可读标签。如果此属性没有被设置,那么改为使用为应用程序整体设置的标签(见<application>元素的label属性)。
The broadcast receiver's label — whether set here or by the <application> element — is also the default label for all the receiver's intent filters (see the <intent-filter> element's label attribute).
广播接收器的标签——不管在这里设置还是通过<application>元素——也是用于所有接收器的意图过滤器的默认标签(见<intent-filter>元素的label属性)。
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.
标签应该被设置为一个指向字符串资源的引用,使它可以像用户界面中的其它字符串那样被本地化。然而,作为一种便利当你正在开发应用程序时,它还可以被设置为一个原始字符串。
* android:name
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.
实现广播接收器的类,一个BroadcastReceiver子类的名称。它应该是一个完全修饰类名(诸如,"com.example.project.ReportReceiver")。然而,作为简写,如果名称的第一个字符是一个点号(例如,". ReportReceiver"),那么它被尾加到<manifest>元素指定的包名后。
Once you publish your application, you should not change this name (unless you've set android:exported="false").
一旦你发布你的应用程序,你不应该改变这个名称(除非你已经设置了android:exported="false")。
There is no default. The name must be specified.
没有默认值。该名称必须被指定。
* android:permission
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.
权限的名称,广播器必须拥有这个权限来发送消息到广播接收器。如果这个属性没有被设置,那么被<application>元素的permission属性设置的权限应用到广播接收器。如果两个回溯性都没有被设置,那么接收器不被一个权限保护。
For more information on permissions, see the Permissions section in the introduction and a separate document, Security and Permissions.
想获得关于权限的更多信息,请参见介绍中的权限章节以及单独的文档,安全与权限。
* android:process
The name of the process in which the broadcast receiver should 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 each component can override the default with its own process attribute, allowing you to spread your application across multiple processes.
广播接收器应该运行在的进程的名称。通常,一个应用程序的所有组件运行在为应用程序创建的默认进程中。它拥有与应用程序包相同的名称。<application>元素的process属性可以为所有组件设置一个不同的默认值。但每个组件可以用它自己的process属性覆盖该默认值,允许你跨多个进程延展你的应用程序。
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 broadcast receiver runs in that process. If the process name begins with a lowercase character, the receiver 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.
如果赋给此属性的名称以一个冒号(':')开头,那么对于应用程序私有的一个新进程被创建,当需要它并且广播接收器运行在那个进程中时。如果进程名称以一个小写字符开头,那么接收器将运行在那个名称的全局进程中,假设它拥有权限这样做。它允许不同应用程序的组件共享一个进程,降低资源使用率。
* introduced in:
* 引入:
API Level 1
API级别1
Except as noted, this content is licensed under Apache 2.0. For details and restrictions, see the Content License.
除特别说明外,本文在Apache 2.0下许可。细节和限制请参考内容许可证。
Android 4.0 r1 - 14 Feb 2012 21:12
-------------------------------
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.
(此页部分内容基于Android开源项目,以及使用根据创作公共2.5来源许可证描述的条款进行修改)
(本人翻译质量欠佳,请以官方最新内容为准,或者参考其它翻译版本:
* ソフトウェア技術ドキュメントを勝手に翻訳
http://www.techdoctranslator.com/android
* Ley's Blog
http://leybreeze.com/blog/
* 农民伯伯
http://www.cnblogs.com/over140/
* Android中文翻译组
http://androidbox.sinaapp.com/
)
那些年,那些你不知道也不需要知道的事。
【翻译】(62)service元素
see
http://developer.android.com/guide/topics/manifest/service-element.html
原文见
http://developer.android.com/guide/topics/manifest/service-element.html
-------------------------------
<service>
service元素
-------------------------------
* syntax:
* 语法:
-------------------------------
<service 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" >
. . .
</service>
-------------------------------
* contained in:
* 被包含在:
<application>
* can contain:
* 可以包含:
<intent-filter>
<meta-data>
* description:
* 描述:
Declares a service (a Service subclass) as one of the application's components. Unlike activities, services lack a visual user interface. They're used to implement long-running background operations or a rich communications API that can be called by other applications.
声明一个服务(一个Service子类)作为应用程序的组件之一。不像活动那样,服务缺少一个可视化用户界面。它们被用于实现长时间运行的后台操作或一个可以被其它应用程序调用的富通信API。
All services must be represented by <service> elements in the manifest file. Any that are not declared there will not be seen by the system and will never be run.
所有服务必须在清单文件中用<service>元素表现。任意在那里没有被声明的服务将不会被系统看到并且将从不被运行。
* attributes:
* 属性:
* android:enabled
Whether or not the service can be instantiated by the system — "true" if it can be, and "false" if not. The default value is "true".
服务是否可以被系统实例化——"true"如果它可以,而"false"如果它不可以。默认值为"true"。
The <application> element has its own enabled attribute that applies to all application components, including services. The <application> and <service> attributes must both be "true" (as they both are by default) for the service to be enabled. If either is "false", the service is disabled; it cannot be instantiated.
<application>元素拥有它自己的enabled属性,它应用到所有应用程序组件,包括服务。<application>和<service>的属性必须都为"true"(正如默认下它们都是)使服务被使能。如果其中一个是"false",服务被屏蔽;它不能被实例化。
* android:exported
Whether or not components of other applications can invoke the service or interact with it — "true" if they can, and "false" if not. When the value is "false", only components of the same application or applications with the same user ID can start the service or bind to it.
其它应用程序的组件是否可以调用该服务或与它交互——"true"如果它们可以,而"false"如果它不可以。当该值为"false"时,只有相同应用程序或带有相同用户ID的应用程序的组件才可以启动服务或绑定到它。
The default value depends on whether the service contains intent filters. The absence of any filters means that it can be invoked only by specifying its exact class name. This implies that the service is intended only for application-internal use (since others would not know the class name). So in this case, the default value is "false". On the other hand, the presence of at least one filter implies that the service is intended for external use, so the default value is "true".
默认值依赖于服务是否包含意图过滤器。不存在任意过滤器意味着只可以通过指定它的精确类名来调用它。这暗示服务倾向于仅供应用程序内部使用(因为其它应用程序不知道类名)。所以在这种情况下,默认值为"false"。另一方面,存在至少一个过滤器暗示服务倾向于供外部使用,所以默认值为"true"。
This attribute is not the only way to limit the exposure of a service to other applications. You can also use a permission to limit the external entities that can interact with the service (see the permission attribute).
这个属性不只是限制服务对其它应用程序的暴露的唯一方式。你还可以使用权限来限制可以与服务交互的外部实体(见permission属性)。
* android:icon
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).
代表服务的图标。这个属性必须被设置为指向包含图片定义的可绘画对象资源的引用。如果它没有被设置,那么改为使用为应用程序整体指定的图标(见<application>元素的icon属性)。
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).
服务的图标——不管在这里设置还是通过<application>元素——也是用于所有服务的意图过滤器的默认图标(见<intent-filter>元素的icon属性)。
* android:label
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).
用于服务的名称,它可以被显示给用户。如果这个属性没有被设置,那么改为使用为应用程序整体设置的标签(见<application>元素的label属性)。
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).
服务的标签——不管在这里设置还是通过<application>元素——也是用于所有服务的意图过滤器的默认标签(见<intent-filter>元素的label属性)。
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.
标签应该被设置为一个指向字符串资源的引用,使它可以像用户界面中的其它字符串那样被本地化。然而,作为便利当你正在开发应用程序时,它还可以被设置为一个原始字符串。
* android:name
The name of the Service subclass that implements the service. This should be a fully qualified class name (such as, "com.example.project.RoomService"). However, as a shorthand, if the first character of the name is a period (for example, ".RoomService"), it is appended to the package name specified in the <manifest> element.
实现服务的Service子类的名称。它应该是一个完全修饰类名(诸如,"com.example.project.RoomService")。然而,作为简写,如果名称的第一个字符是一个点号(例如,".RoomService"),那么它被尾加到<manifest>元素中指定的包名后。
Once you publish your application, you should not change this name (unless you've set android:exported="false").
一旦你发布你的应用程序,你应该不改变这个名称(除非你已经设置了android:exported="false")。
There is no default. The name must be specified.
没有默认值。该名称必须被指定。
* android:permission
The name of a permission that that an entity must have in order to launch the service or bind to it. If a caller of startService(), bindService(), or stopService(), has not been granted this permission, the method will not work and the Intent object will not be delivered to the service.
权限的名称,一个实体必须拥有它以便启动服务或绑定到它。如果startService(),bindService()或stopService()的调用方还不曾被授权给这个权限,那么该方法将不能工作并且Intent对象将不被传递给该服务。
If this attribute is not set, the permission set by the <application> element's permission attribute applies to the service. If neither attribute is set, the service is not protected by a permission.
如果这个属性没有被设置,那么被<application>元素的permission属性设置的权限应用到该服务。如果两个属性都没有被设置,那么服务不被一个权限保护。
For more information on permissions, see the Permissions section in the introduction and a separate document, Security and Permissions.
想获得关于权限的更多信息,请参见介绍中的权限章节以及单独的文档,安全与权限。
* android:process
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.
服务打算运行在的进程的名称。通常,一个应用程序的所有组件运行在为应用程序创建的默认进程中。它拥有与应用程序包相同的名称。<application>元素的process属性可以为所有组件设置一个不同的默认值。但组件可以用它自己的process属性覆盖该默认值,允许你跨多个进程延展你的应用程序。
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.
如果赋给这个属性的名称以一个冒号(':')开头,那么对于应用程序私有的一个新进程被创建,当需要它而服务运行在那个进程中时。如果进程名称以小写字符开头,那么服务将运行在那个名称的全局进程中,假设它拥有权限这样做。这允许不同应用程序里的组件共享一个进程,降低资源使用率。
* see also:
* 另见:
<application>
<activity>
* introduced in:
* 引入:
API Level 1
API级别1
Except as noted, this content is licensed under Apache 2.0. For details and restrictions, see the Content License.
除特别说明外,本文在Apache 2.0下许可。细节和限制请参考内容许可证。
Android 4.0 r1 - 14 Feb 2012 21:12
-------------------------------
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.
(此页部分内容基于Android开源项目,以及使用根据创作公共2.5来源许可证描述的条款进行修改)
(本人翻译质量欠佳,请以官方最新内容为准,或者参考其它翻译版本:
* ソフトウェア技術ドキュメントを勝手に翻訳
http://www.techdoctranslator.com/android
* Ley's Blog
http://leybreeze.com/blog/
* 农民伯伯
http://www.cnblogs.com/over140/
* Android中文翻译组
http://androidbox.sinaapp.com/
)