Accessibility and Android WebView
Asked Answered
B

5

24

Is Accessibility enabled for Android WebView? Can anyone tell how to make a WebView accessible?

Banwell answered 17/5, 2012 at 11:31 Comment(0)
P
9

The Android webview accessibility is enabled via javascript injection in Honeycomb and above (as pointed out by alanv). The user must enable it by:

  • Turning on Accessibility mode, including 'Explore by Touch' in 4.0+.
  • Enabling 'Enhanced Web Accessibility', or, on older devices, 'Inject Web Scripts'.

This works by injecting javascript into each loaded pages via <script> tags. Note that you will have to be careful, as not all content will play nice with this javascript, and the injection will fail in some edge cases.

Psaltery answered 11/7, 2013 at 17:47 Comment(0)
E
5

You can extend the WebView class to implement Accessibility API methods.

http://developer.android.com/guide/topics/ui/accessibility/apps.html#custom-views

Endosteum answered 29/6, 2012 at 17:53 Comment(0)
V
4

I also ran into this issue on 4.0 devices. I ended up placing a TextView on top of the WebView, making the TextView background and text transparent. The text content of the TextView being set to the content of WebView with all HTML tags stripped out.

A most inelegant solution, I know, but hey it works....

Viceroy answered 13/7, 2012 at 0:47 Comment(0)
P
2

No, the WebView is not accessible from the built-in TalkBack service, at least as of Android version 4.0. Instead, blind users are instructed to use something like Mobile Accessibility for Android, which provides a spoken browsing interface. I would suggest making your content available to other processes, allowing blind users to view the content in their browser of choice. I did this by starting an intent to view the content:

public static void loadUrlInBrowser(Context c, Uri uri) {
    Intent i = new Intent(Intent.ACTION_VIEW);
    i.setDataAndType(uri, "text/html");
    c.startActivity(i);
}

Alternatively, you can set the content description of the WebView. Note that this only seems to work in pre 4.0 versions of android. I've found that 4.0 devices keep either say WebView or nothing at all.

Psaltery answered 10/7, 2012 at 19:21 Comment(2)
WebView is keyboard accessible in Honeycomb and above by enabling Settings > Accessibility > Inject web scripts. In Jelly Bean and above, WebView is keyboard accessible (and touch explorable when JS is enabled) by enabling Settings > Accessibility > Enhance web accessibility.Gans
@Gans Is both paths the same on newer Android APIs? I cannot find them on Android 11!Araarab
J
1

I know how to access web view content by Accessibility API, when AccessibilityNodeInfo.getText() is null or "null", call AccessibilityNodeInfo.getContentDescription().

simple code:

private String getTextOrDescription(AccessibilityNodeInfo info) {
    String text = String.valueOf(info.getText());

    if (isEmptyOrNullString(text)) {
        text = String.valueOf(info.getContentDescription());
    }
    return text;
}

private boolean isEmptyOrNullString(String text) {
    if (TextUtils.isEmpty(text) || text.equalsIgnoreCase("null")) {
        return true;
    }
    return false;
}

getContentDescription() can get the web view content.

sorry for my poor english.

Jacquesjacquet answered 30/11, 2016 at 3:58 Comment(1)
Well this is not true anymore. at least on ChromeHypethral

© 2022 - 2024 — McMap. All rights reserved.