Access-Control-Allow-Origin Error At Android 4.1 Access-Control-Allow-Origin Error At Android 4.1 android android

Access-Control-Allow-Origin Error At Android 4.1


you need to do something like

if (Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN)   wv.getSettings().setAllowUniversalAccessFromFileURLs(true);


@I am Developer and the others who are facing the same problem.

Slushis solution works fine. But if you want to compile against and support systems below API11 you have to add the following:

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);    }}

This will load and invoke the method at runtime, so you can compile with e.g. Android 2.3.3.


Are your web services hosting from the same domain ? I used to get this error while making an ajax call to a service under a different domain.If you have control on the web service, you can set Access-Control-Allow-Origin: *in the header, (although this way is not a secure way of doing so.)