3

When I try to run some web pages in WebView, I get "Unsafe JavaScript attempt to access frame with URL data" error.

I read (somewhere on the web) that I should set the --allow-file-access-from-files switch. On Android API16 and up I have the setAllowUniversalAccessFromFileURLs option but not on lower versions (where I get the error).

Is there a way to handle it on android2.3.3 for example?

Asaf Pinhassi
  • 15,177
  • 12
  • 106
  • 130

1 Answers1

0

You can use below:

if (Build.VERSION.SDK_INT >= 16) {  
    Class<?> clazz = webView.getSettings().getClass();
    Method method = clazz.getMethod("setAllowUniversalAccessFromFileURLs", boolean.class);
    if (method != null) {
        method.invoke(webView.getSettings(), true);
    }
}
josliber
  • 43,891
  • 12
  • 98
  • 133
Gu Zhenfu
  • 1
  • 2