Android 来自webview中自定义html的Ajax调用未使用shouldInterceptRequest进行
我有一个简单的应用程序,我加载一个带有HTML的WebView,其中包含一个按钮上的ajax调用。 我希望我的函数“shouldInterceptRequest”能够捕获该请求并发送回一些内容,目前它是一个字符串,但它将是一个字符串 以下是我的WebViewActivity代码: 公共类WebViewActivity扩展了活动{Android 来自webview中自定义html的Ajax调用未使用shouldInterceptRequest进行,android,ajax,webview,Android,Ajax,Webview,我有一个简单的应用程序,我加载一个带有HTML的WebView,其中包含一个按钮上的ajax调用。 我希望我的函数“shouldInterceptRequest”能够捕获该请求并发送回一些内容,目前它是一个字符串,但它将是一个字符串 以下是我的WebViewActivity代码: 公共类WebViewActivity扩展了活动{ private WebView webView; private Uri picUri; public void onCreate(Bundle savedInsta
private WebView webView;
private Uri picUri;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
//webView.loadUrl("http://www.google.com");
String newHTML = "<!doctype html><html><head>"+
"<script src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js\"></script>"+
"<script>"+
"function myCall() {"+
"var request = $.ajax({"+
"url: \"ajax.php\","+
"type: \"GET\","+
"dataType: \"html\""+
"});"+
"request.done(function(msg) {"+
"$(\"#mybox\").html(msg);"+
"});"+
"request.fail(function(jqXHR, textStatus) {"+
"alert( \"Request failed: \" + textStatus );"+
"});"+
"}"+
"</script>"+
"<meta charset=\"utf-8\" />"+
"<title>My jQuery Ajax test</title>"+
"<style type=\"text/css\">"+
"#mybox {"+
"width: 300px;"+
"height: 250px;"+
"border: 1px solid #999;"+
"}"+
"</style>"+
"</head>"+
"<body>"+
"The following div will be updated after the call:<br />"+
"<div id=\"mybox\">"+
"</div>"+
"<input type=\"button\" value=\"Update\" />"+
"</body>"+
"</html>";
webView.loadData(newHTML, "text/html", "UTF-8");
webView.setWebViewClient(new WebViewClient() {
@Override
public WebResourceResponse shouldInterceptRequest (final WebView view, String url) {
return super.shouldInterceptRequest(view, url+" captured");
}
});
}
}
出于某种原因,我没有捕捉到ajax调用。
我做错了什么?清单是我的问题!我没有网络部分!所以我做的是在清单中,最后添加: 网络: *
因此,这种方式的工作原理是,在缓存网络之前我拥有的任何东西,如果没有什么东西,就无法知道该怎么做。有了这句话,无论缓存中没有什么东西,我们都可以从网络中获得它。如何添加NETOWRK:*在清单中,请给出一些例子。