1
我想在Android上創建簡單的兒童安全瀏覽器,並且我想在使用此api加載前檢查每個網址:https://www.mywot.com/wiki/API。但有時在點擊url後啓動加載這個鏈接的無限循環。 我嘗試重寫shouldOverrideUrlLoading這樣的:鑑於Android WebView - 點擊後無限循環
private class BrowserWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
loadUrl(url);
return true;
}
}
}
private interface UrlCheckListener {
void urlChecked(boolean isGood);
}
private void loadUrl(String query) {
String safeUrl = UrlCheckerUtils.getSafeUrlFromQuery(query);
checkUrlBeforeLoad(safeUrl, valid -> {
if (isViewAttached()) {
if (valid) {
getView().loadPageByUrl(safeUrl);
} else {
getView().showError();
}
}
});
}
private void checkUrlBeforeLoad(String url, UrlCheckListener listener) {
try {
URI uri = new URI(url);
String domain = uri.getHost() + "/";
wotService.getLinkReputation(domain)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(wotResponse -> listener.urlChecked(wotResponse.isSafe()));
} catch (URISyntaxException e) {
Timber.e(e, "Error while parsing url");
}
}
loadPageByUrl:
@Override
public void loadPageByUrl(String url) {
webView.loadUrl(url);
}
你能幫我解決這個問題嗎?
in'loadPageByUrl',你調用'loadUrl',然後調用'loadPageByUrl' – Danh
@Danh,我該如何解決它? – shmakova
我對Android不熟悉,我無法給你一個正確的答案。嘗試使用調試器或在那裏找到一些教程 – Danh