Accessibility service declaration
In order to be treated as an accessibility service, your application must include the
service element (rather than the activity element) within the application element in its manifest. In addition, within the service
element, you must also include an accessibility service intent filter.
For compatiblity with Android 4.1 and higher, the manifest must also
request the BIND_ACCESSIBILITY_SERVICE permission as shown in the following sample:<application> <serviceandroid:name=".MyAccessibilityService" android:label="@string/accessibility_service_label" android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE"> <intent-filter> <actionandroid:name="android.accessibilityservice.AccessibilityService"/> </intent-filter> </service> <uses-permissionandroid:name="android.permission.BIND_ACCESSIBILITY_SERVICE"/></application>
These declarations are required for all accessibility services deployed on Android 1.6 (API Level 4) or higher.
Accessibility service configuration
Accessibility
services must also provide a configuration which specifies the types of
accessibility events that the service handles and additional
information about the service. The configuration of an accessibility
service is contained in the
AccessibilityServiceInfo class. Your service can build and set a configuration using an instance of this class and setServiceInfo() at runtime. However, not all configuration options are available using this method.
Beginning with Android 4.0, you can include a
<meta-data>
element in your manifest with a reference to a configuration file,
which allows you to set the full range of options for your accessibility
service, as shown in the following example:<serviceandroid:name=".MyAccessibilityService"> ... <meta-data android:name="android.accessibilityservice" android:resource="@xml/accessibility_service_config"/></service>
This meta-data element refers to an XML file that you create in your application’s resource directory (
<project_dir>/res/xml/accessibility_service_config.xml). The following code shows example contents for the service configuration file:<accessibility-servicexmlns:android="http://schemas.android.com/apk/res/android" android:description="@string/accessibility_service_description" android:packageNames="com.example.android.apis" android:accessibilityEventTypes="typeAllMask" android:accessibilityFlags="flagDefault" android:accessibilityFeedbackType="feedbackSpoken" android:notificationTimeout="100" android:canRetrieveWindowContent="true" android:settingsActivity="com.example.android.accessibility.ServiceSettingsActivity"/>
For
more information about the XML attributes which can be used in the
accessibility service configuration file, follow these links to the
reference documentation:
android:descriptionandroid:packageNamesandroid:accessibilityEventTypesandroid:accessibilityFlagsandroid:accessibilityFeedbackTypeandroid:notificationTimeoutandroid:canRetrieveWindowContentandroid:settingsActivity
For more information about which configuration settings can be dynamically set at runtime, see the
AccessibilityServiceInfo reference documentation.
No comments:
Post a Comment