(Transfer) AndroidManifest.xml file details (service)

Reprinted from: http://blog.csdn.net/think_soft/article/details/7584895

 

Syntax (SYNTAX):

<serviceAndroid: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>

is contained in (CONTAINED IN):

<application>

Possible elements (CAN CONTAIN):

<intent-filter>

<meta-data>

Description (DESCRIPTION):

This element is used to declare a service (a subclass of the Service class) as one of the application's components. Unlike activities, services have no visible user interface. They are used to implement long-lived background operations, or to provide communication APIs that can be called by other applications.

All services must be represented by the <service> element in the manifest file. Any service not declared in the manifest will not be seen by the system and will not be run.

Attributes (ATTRIBUTES):

android:enabled

This property is used to indicate whether the service can be instantiated. If set to true, it can be instantiated, otherwise it cannot be instantiated. The default value is true.

The <application> element has its own enabled attribute, which applies to all components in the application, including the service component. For a service to be enabled, the enabled attributes of both the <application> and <service> elements must be true (the default is true). If an element's enabled attribute is set to false, the service is disabled and cannot be instantiated.

android:exported

This property is used to indicate whether the service can be called by or interact with other application components. Can be called or interacted with if set to true, otherwise not. When set to false, only components of the same application or applications with the same user ID can start or bind the service.

Its default value depends on the filters contained in the service. No filter means that the service can only be called by specifying an explicit class name, which means that the service can only be used inside the application (because other external consumers will not know the class name of the service), so this In this case, the default value of this property is false. On the other hand, if at least one filter is included, it means that the service can provide services to other external applications, so the default value is true.

这个属性不是限制把服务暴露给其他应用程序的唯一方法。还可以使用权限来限制能够跟该服务交互的外部实体。

android:icon

这个属性定义了一个代表服务的图标,它必须要引用一个包含图片定义的可绘制资源。如果这个属性没有设置,则会使用<application>元素的icon属性所设定的图标来代替。

无论是<application>元素设置的图标,还是<service>元素所设置的图标,它们都是该服务所有的Intent过滤器的默认图标。

android:label

这个属性用于设定一个要显示给用户的服务的名称。如果没有设置这个属性,则会使用<application>元素的label属性值来代替。

无论是<service>设定的标签,还是<application>元素设定的标签,它们都是该服务所有的Intent过滤器的默认标签。

这个标签应用引用一个字符串资源,以便它能够像用户界面中的字符串一样能够被本地化。但是,为了开发应用程序方便,也可以使用原生字符串来设置这个属性。

android:name

这个属性用于指定实现该服务的Service子类的类名。它应该是完整的Java类名(如:com.example.project.RoomService)。但是,也可以使用简写(如:.RoomService),系统会把<manifest>元素中package属性所设定的值添加到简写名称的前面。

一旦发布了应用程序,就不应该改变这个名称(除非android:exported=”false”)。

这个属性没有默认值,名称必须要指定。

android:permission

This property defines the permissions that the entity that wants to start or bind the service must have. If the caller's startService(), bindService(), and stopService() methods are not granted this permission, these methods will not work and Intent objects will not be sent to the service.

If this attribute is not set, the permissions set through the <appliction> element's permission attribute will apply to the service. If the <application> element also does not have permissions set, the service is not protected by permissions.

android:process

This property is used to set the name of the process the service is running on. Typically, all components of an application run in a process created for the application with the same process name as the application's package name. The process attribute of the <application> element can set a different default name for all components of the application. But each component's own process attribute can override this default value, which allows the application to be separated into multiple processes.

 

If the property value starts with ":", the system will create a new, application-private process when needed, and the service will also run in this process. If the property value starts with a lowercase letter, then the service runs in the global process named after the property value, which provides permission to make it work. This allows different application components to share the process, thereby reducing resource usage.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326265306&siteId=291194637