Android Accessibility Accessibility Brief Introduction _android

Source: Internet
Author: User

Android Accessibility Accessibility

Accessibility:

Many Android users have a variety of situations that cause them to interact with their phones in different ways.

This includes users whose eyesight, physical, and age problems cause them to not be able to see the full screen or to use touch screens, and also include users who are less able to receive voice information and hints.

Android offers accessibility features and services to help these users more simply manipulate devices, including text-to-speech (this does not support Chinese), tactile feedback, gesture manipulation, trackball and handle manipulation.

Developers can use these services to make programs work better.

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

The accessibility service can provide these enhancements for all applications, a set of applications, or a single application.

In the official document, there are three articles about accessibility, as long as the third article on the use of Accessibilityservice:

Accessibilityservice is simple to use:

1. Create a new class to inherit Accessibilityservice and register it in the Androidmanifest file:

<application> 
 <service android:name= ". Myaccessibilityservice " 
   android:label=" @string/accessibility_service_label "> 
  <intent-filter> 
   <action android:name= "Android.accessibilityservice.AccessibilityService"/> 
  </intent-filter > 
 </service> 
 <uses-permission android:name= "Android.permission.BIND_ACCESSIBILITY_SERVICE"/ > 
</application> 

Add the subclass Myaccessibilityservice that inherits the Accessibilityservice under the <application> tab, adding the appropriate permissions.

2. Implement several important overloaded methods in subclass Myaccessibilityservice:

onserviceconnected ()-optional. The system will call this method when it is successfully connected to your service, in which you can do initialization work, such as sound vibration management of the device, or call Setserviceinfo () for configuration work.

Onaccessibilityevent ()-Must. Through this function can receive the system sends the Accessibilityevent, receives the accessibilityevent is filtered, the filtering is when configures the work to set.

Oninterrupt ()-Must. This is invoked when the system wants to interrupt a accessibilityservice return response. are called multiple times throughout the life cycle.
Onunbind ()-optional. This accessibilityservice will be invoked when the system is going to close. Do some of the work of releasing resources in this method.

3. Configuration work

Generally in the onserviceconnected () method. /android-sample/apidemos/com.example.android.apis.accessibility.clockbackservice Configuration Code:

private void Setserviceinfo (int feedbacktype) { 
  Accessibilityserviceinfo info = new Accessibilityserviceinfo (); 
  We are interested in the all types of accessibility events. 
  Info.eventtypes = Accessibilityevent.types_all_mask; 
  We want to provide specific type of feedback. 
  Info.feedbacktype = Feedbacktype; 
  We want to receive the events in a certain interval. 
  Info.notificationtimeout = Event_notification_timeout_millis; 
  We want to receive accessibility events only from certain packages. 
  Info.packagenames = Package_names; 
  Setserviceinfo (info); 
} 

You need to create a Accessibilityserviceinfo object that sets up the listener system event type, the service feedback type (vibration, voice, sound), the event interval, and the name of the package you want to listen to (or the application). The last Call to Setserviceinfo () is set.

Note: Starting with Android4.0, developers can add <meta-data> tags to the tag to indicate the location of the configuration file in the Androidmanifest, sample code:

<service android:name= ". Myaccessibilityservice "> ... 
 <meta-data 
  android:name= "Android.accessibilityservice" 
  android:resource= "@xml/accessibility_service _config "/> 
</service> 

And then in/res/xml/accessibility_service_config.xml

<accessibility-service xmlns: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= "MB" 
  android: Canretrievewindowcontent= "true" 
  android:settingsactivity= " Com.example.android.accessibility.ServiceSettingsActivity " 
/> 

More details can be found in the official documentation, or can be seen in the samples of two examples: Clockbackservice, Taskbackservice.

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.