Change the "Web page unavailable" page when there is no internet connection
Good afternoon.
I'm new to android. A question arose:
There is actually webview
that will open a certain site.
If you turn off the Internet, the window "Web page unavailable" appears, etc.
Is it possible to change this particular page?
2
2 answers
You can catch the error by blocking the WebView onReceivedError
, then replace html
-ky or close webview
webView.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
//logic
}
});
4
Author: Андроид Андроид, 2016-03-01 07:35:28
You can add a check for the presence of an Internet connection and, if there is no Internet connection, feed the necessary information to WebView
. Eg:
if (isConnected()) {
//Стандартная Ваша загрузка
} else {
// Показываем текст:
webView.loadData("Извините, интернета нет, вот мое сообщение/пожелание", "text/html", "utf-8");
//Либо кормим подготовленную страницу:
//webView.loadUrl("file:///android_asset/myPage.html");
}
1
Author: VAndrJ, 2016-03-01 07:36:58