且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

android:启用和服务

更新时间:2023-02-13 15:14:23

新的 SAF(存储访问框架)是使用 android:enabled 属性的一个很好的例子.http://developer.android.com/guide/topics/providers/document-provider.html

android:enabled 属性设置为在资源文件.此属性的目的是禁用运行 Android 4.3 或更低版本的设备上的提供程序.例如,

android:enabled="@bool/atLeastKitKat"

除了包括这个清单中的属性,您需要执行以下操作:在 res/values/下的 bool.xml 资源文件中,添加以下行:

false</bool>

在 res/values-v19/下的 bool.xml 资源文件中,添加以下行:

true

I m currently learning how create and use services on android. I looked on the android SDK for further help and i found the android:enable=[true | false].

in the SDK is said that:

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

So i would like to know what is the interest of/ why (in general)

  • setting the application enables as "false".
  • setting the service enable as "false".

I say that if we put service enable as false there is no way to call that service, so why we create that service in the first place?

Thank you and sorry for such long message.

New SAF(Storage Access Framework) is a good example of use of android:enabled attribute. http://developer.android.com/guide/topics/providers/document-provider.html

The android:enabled attribute set to a boolean value defined in a resource file. The purpose of this attribute is to disable the provider on devices running Android 4.3 or lower. For example,

android:enabled="@bool/atLeastKitKat" 

In addition to including this attribute in the manifest, you need to do the following: In your bool.xml resources file under res/values/, add this line:

<bool name="atLeastKitKat">false</bool> 

In your bool.xml resources file under res/values-v19/, add this line:

<bool name="atLeastKitKat">true</bool>