android中的webview在加載url時多次加載一次。 以下是代碼。WebView在android中加載url不止一次android
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
if (url.contains(".pdf")) {
String[] spliturl = url.split("http://someurl/");
String googleurl = "http://docs.google.com/viewer?embedded=true&url=";
System.out.println("Google Url"+googleurl);
System.out.println("spliturl"+spliturl[1]);
view.loadUrl(googleurl+spliturl[1]);
}
else
view.loadUrl(url);
return true;
}
});
我分裂的網址,因爲它包含多個網址要通過谷歌文檔查看器呈現PDF文檔。 第一次url被正確拆分並且url被連接在google文檔中打開,但webview在spliturl [1]處通過給出ArrayIndexOutOfBoundsException再次執行。 有人能讓我知道爲什麼這是再次執行。 謝謝。
可能會更樣本,如果你直接在打開PDF導航器: 字符串googleDocsUrl =「http://docs.google.com/viewer?url="+documentUrl; \t \t \t Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.parse(googleDocsUrl),「text/html」); startActivity(intent); – 2012-04-06 08:05:07