Android <service>属性值含义翻译

英文不太好,看的文档时间长了,总会忘记,以免自己忘记了,这里还是记录下来吧。同时分享给各位看英文,又爱忘记的开发者,本文主要借助google翻译,如有不对,请谅解。
介绍和属性都是我个人参照文档和平时开发经验的理解。如有不对,请提醒我修正。谢谢大家。

(1)先简要翻译一下它的各个属性吧

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

attributes:

android:description

 A string that describes the service to users. 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.

翻译:向用户描述服务的字符串。 标签应设置为字符串资源的引用,以便可以像用户界面中的其他字符串一样进行本地化。
介绍:就是像用户描述的一个内容。建议用@string/test_service这样,方便做国际化。
**使用:**android:description=”@string/test_service”

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".
    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. 

翻译:是否可以由系统实例化服务 - 如果可以,则为“true”,否则为“false”。 默认值为“true”。
元素有自己的enabled属性,适用于所有应用程序组件,包括服务。 要启用服务,和属性必须都为“true”(默认情况下都为true)。 如果其中一个是“false”,则服务被禁用; 它不能被实例化。
介绍:是否可以被系统实例化。
**使用:**android:enabled=[“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.
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".
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). 

翻译:其他应用程序的组件是否可以调用服务或与其交互 - 如果可以,则为“true”,否则为“false”。 当值为“false”时,只有具有相同用户ID的同一应用程序或应用程序的组件才能启动服务或绑定到该服务。
默认值取决于服务是否包含意图过滤器。 没有任何过滤器意味着它只能通过指定其确切的类名称来调用。 这意味着该服务仅用于应用程序内部使用(因为其他人不知道类名)。 因此,在这种情况下,默认值为“false”。 另一方面,至少存在一个过滤器意味着该服务打算供外部使用,因此默认值为“true”。

此属性不是将服务的曝光限制为其他应用程序的唯一方法。 您还可以使用权限限制可与服务交互的外部实体(请参阅权限属性)。
介绍:服务是否可以被其它应用程序调用。
**使用:**android:exported=[“true” | “false”]

android:permission

    The name of a permission 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.

    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.

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

翻译:实体必须具有以启动服务或绑定到其的权限的名称。 如果startService(),bindService()或stopService()的调用者未被授予此权限,则该方法将不会工作,并且Intent对象将不会传递到服务。

如果未设置此属性,则由元素的权限属性设置的权限将应用于服务。 如果未设置任何属性,则服务不受权限保护。

有关权限的详细信息,请参阅简介中的“权限”部分和单独的文档“安全和权限”。
介绍:服务的权限声明。
**使用:**android:permission=”string”

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.
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. 

翻译:运行服务的进程的名称。 通常,应用程序的所有组件都在为应用程序创建的默认进程中运行。 它与应用程序包具有相同的名称。 元素的process属性可以为所有组件设置不同的默认值。 但组件可以使用自己的进程属性覆盖默认值,从而允许您跨多个进程扩展应用程序。
如果分配给此属性的名称以冒号(’:’开头),则在需要并在该进程中运行服务时,将创建对应用程序为专用的新进程。 如果进程名称以小写字符开头,则该服务将在该名称的全局进程中运行,前提是它具有这样做的权限。 这允许不同应用程序中的组件共享进程,减少资源使用。
介绍:为服务指定进程。
**使用:**android:process=”string”,以:或者小写字符开头(’:’开头的进程属于当前应用的私有进程,其它应用的组件不可以和它跑在同一个进程中,以小写字母开头的属于全局进程,其它应用通过ShareUID方式可以和它跑在同一个进程)。

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.
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. 

翻译:实现服务的服务子类的名称。 这应该是一个完全限定类名(例如,“com.example.project.RoomService”)。 但是,如果名称的第一个字符是句点(例如,“.RoomService”),则将其附加到元素中指定的包名称。
发布应用程式后,您不应更改此名称(除非您已设定android:exported =“false”)。

没有默认值。 必须指定名称。
介绍:进程的名称。
**使用:**android:name=”string”,用类似“com.example.project.RoomService”或者“.RoomService”。

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).
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).

翻译:表示服务的图标。 此属性必须设置为对包含图像定义的可绘制资源的引用。 如果未设置,则将使用为应用程序整体指定的图标(请参阅元素的图标属性)。
服务的图标(无论在此处设置还是通过元素)也是所有服务的意图过滤器的默认图标(请参阅元素的图标属性)。
介绍:服务的图标。
**使用:**android:icon=”drawable resource”。

android:isolatedProcess

If set to true, this service will run under a special process that is isolated from the rest of the system and has no permissions of its own. The only communication with it is through the Service API (binding and starting).

翻译:如果设置为true,此服务将在与系统其他部分隔离的特殊进程下运行,并且没有自己的权限。 与它唯一的通信是通过服务API(绑定和启动)。
介绍:是否在特殊进程下运行。
**使用:**android:isolatedProcess=[“true” | “false”]。

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).
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.

翻译:可以向用户显示的服务的名称。 如果未设置此属性,则将使用整个应用程序的标签集(请参阅元素的label属性)。
服务的标签 - 无论是在这里设置还是通过元素 - 也是所有服务的意图过滤器的默认标签(参见元素的label属性)。

标签应设置为字符串资源的引用,以便可以像用户界面中的其他字符串一样进行本地化。 但是,为了方便开发应用程序,它还可以设置为原始字符串。
介绍:服务名称标签。
**使用:**android:name=”string”。

猜你喜欢

转载自blog.csdn.net/u012489412/article/details/53926889
今日推荐