Brief introduction to Android accessibility accessibility accessibility

Android accessibility accessibility accessibility accessibility

Accessibility:

Many Android users have to interact with their mobile phones in different ways because of various situations.

This includes some users who can't see the complete screen or use the touch screen due to visual, physical and age problems, as well as users with weak hearing ability who can't receive voice information and prompts well.

Android provides accessibility functions and services to help these users operate the device more easily, including text to speech (this does not support Chinese), tactile feedback, gesture operation, trackball and handle operation.

Developers can use these services to make the program more useful.

Developers can build their own accessibility services, which can enhance usability, such as voice prompts, physical feedback, and other optional operation modes.

Accessibility services can provide these enhancements for all applications, a group of applications, or a single application.

In the official document, there are three articles about accessibility. Here is the third article about the use of Accessibility Service:

Accessibilityservice is easy to use:

1. Create a new class that inherits accessibilityservice and register it in the androidmanifest file:

Under the < Application > tab, add myaccessibilityservice, a subclass that inherits accessibilityservice, and add corresponding permissions.

2. Implement several important overloaded methods in the subclass myaccessibilityservice:

Onserviceconnected() - optional. The system will call this method when you successfully connect to your service. In this method, you can do initialization, such as sound vibration management of the device, or call setserviceinfo() for configuration.

Onaccessibilityevent() - required. Through this function, you can receive the accessibilityevent sent by the system. The received accessibilityevent is filtered and the filtering is set during configuration.

Oninterrupt() - required. This is called when the system wants to interrupt the response returned by accessibilityservice. It will be called many times in the whole life cycle. Onunbind() - optional. When the system is about to close, this accessibilityservice will be called. In this method, do some work to release resources.

3. Configuration work

This is usually done in the onserviceconnected () method/ Android sample / apidemos / com.example.android.apis.accessibility.clockbackservice configuration code:

You need to create an accessibilityserviceinfo object. Through this object, you can set the event type of the monitoring system, the feedback type of the service (vibration, voice, sound), the event time interval, and the package name (or application) you want to monitor. Finally, call setServiceInfo () to set up.

Note: starting from Android 4.0, developers can indicate the location of the configuration file in the tag by adding the < meta data > tag in the androidmanifest. Sample code:

Then in / RES / XML / accessibility_ service_ config.xml

For more details, please refer to the official documents, or see two examples in samples: clockbackservice and taskbackservice.

Thank you for reading, hope to help you, thank you for your support to this site!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>