1
我有這個簡單的應用程序,我加載了一個WebView的HTML包含一個按鈕上的Ajax調用。 我希望我的功能「shouldInterceptRequest」捕獲該請求,並送點東西回來(現在是一個字符串,但是這將是一個)從webview中的自定義HTML Ajax調用沒有capIn with shouldInterceptRequest
這裏是我的WebViewActivity代碼:
公共類WebViewActivity延伸活動{
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:*請給一些例子。 – user7176550