Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android accessibility IMPORTANT_FOR_ACCESSIBILITY_NO is not respected

In my app I have ad on bottom, in accessibility (talkback) mode I don't want ads to be included. for this I have set this AdView and its parent to IMPORTANT_FOR_ACCESSIBILITY_NO and focusable = false, but it is not respected when app starts (Talkback enabled)the first item that gets focused is this ad.

I request focus to desired item still ad is focused, how can I make this ad not focusable?

like image 416
SCP Avatar asked Sep 16 '15 05:09

SCP


People also ask

What is Android importantForAccessibility?

Android defines android:importantForAccessibility as: Describes whether or not this view is important for accessibility. If it is important, the view fires accessibility events and is reported to accessibility services that query the screen.

What is an accessibility service on Android?

An Accessibility Service assists users with disabilities in using Android devices and apps. It is a long-running privileged service that helps users process information on the screen and lets them to interact meaningfully with a device.

Which of the following accessibility tools comes built in with most Android devices?

TalkBack. TalkBack is Android's built-in screen reader. When TalkBack is on, users can interact with their Android device without seeing the screen. Users with visual impairments may rely on TalkBack to use your app.


3 Answers

This is what I have done to achieve I have blocked descendant focus-ability which ad view gets by default as it get added to the view last. Wrapping the adview in a layout and adding property.

android:descendantFocusability="blocksDescendants"

My requirement was to assign focus to the first element in screen which I achieved using:

firstView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES);
firstView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);

I still agree to the point we should not change focus but this was only in case of ad. The ad is still focusable by touch.

like image 168
Amit Chaudhary Avatar answered Nov 15 '22 19:11

Amit Chaudhary


When you set importantForAccessibility to no, you're only hiding the single view. You want to find the layout for the advertisement, and hide it and all of its descendants.

android:importantForAccessibility="noHideDescendants"

Should you want to do it programmatically, the constant you are looking for is:

IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS

Note: YOU ABSOLUTELY SHOULD NOT, do this. Advertisements are annoying for everyone. Separate is not equal. By hiding information, even annoying information, from VoiceOver you are breaking at least half a dozen WCag 2.0 criteria and making your application less accessible.

like image 37
ChrisCM Avatar answered Nov 15 '22 19:11

ChrisCM


Straight from docs

android:importantForAccessibility Describes whether or not this view is important for accessibility. If it is important, the view fires accessibility events and is reported to accessibility services that query the screen. Note: While not recommended, an accessibility service may decide to ignore this attribute and operate on all views in the view tree.

though that note makes no sense by itself: what is not recommended and by or to whom? but probably means that this feature may not be taken into account by actual accessibility services (Talkback etc). It does not work in API23 but does work in 26 on webviews, from my experience.

like image 30
Boris Gafurov Avatar answered Nov 15 '22 20:11

Boris Gafurov