使用Android webView访问html页面,碰到ajax跨域访问时,仅仅在header中加入

http {  ......  add_header Access-Control-Allow-Origin *;  add_header Access-Control-Allow-Headers X-Requested-With;  add_header Access-Control-Allow-Methods GET,POST,OPTIONS;  ......}

信息,无法解决跨域访问问题,可以尝试给webview设置如下配置,已解决该问题;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN){            webView.getSettings().setAllowUniversalAccessFromFileURLs(true);        }else{            try {                Class<?> clazz = webView.getSettings().getClass();                Method method = clazz.getMethod("setAllowUniversalAccessFromFileURLs", boolean.class);                if (method != null) {                    method.invoke(webView.getSettings(), true);                }            } catch (NoSuchMethodException e) {                e.printStackTrace();            } catch (InvocationTargetException e) {                e.printStackTrace();            } catch (IllegalAccessException e) {                e.printStackTrace();            }        }



更多相关文章

  1. Android解决NDK not configured问题
  2. android studio3.1.3和kotlin1.2.51踩坑(一)
  3. Android解决HAXM安装的问题
  4. as报错
  5. TextView添加Onclick点击无效没反应解决办法
  6. Android(安卓)Studio开发过程中各种问题
  7. android解决Unknown host 'jcenter.bintray.com'问题
  8. android 取消标题 程序意外停解决方法
  9. android dex工具打包Could not reserve enough space for object

随机推荐

  1. Android简单的Timer小例子
  2. 使用代理下载Android SDK
  3. Android 蓝牙开发(九)A2DP基本功能
  4. [Android] 升级了新的android studio之后
  5. xx can be an out parameter, so you mus
  6. android中使用特殊符号
  7. android从sdcard加载.9.png图片
  8. Android 最火高速开发框架AndroidAnnotat
  9. Android APK应用安装原理(2)-查找APK并自
  10. Android(安卓)中与 Touch 事件详解