Last active
August 29, 2015 14:24
-
-
Save deskid/94e504009b373a30253d to your computer and use it in GitHub Desktop.
WebView set default 404 page and some security setting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final String offlineMessageHtml = "DEFINE THIS"; | |
final String timeoutMessageHtml = "DEFINE THIS"; | |
WebView browser = (WebView) findViewById(R.id.webview); | |
browser.setNetworkAvailable(isConnected); | |
browser.setWebViewClient(new WebViewClient() { | |
@Override | |
public boolean shouldOverrideUrlLoading(WebView view, String url) { | |
if (isConnected) { | |
// return false to let the WebView handle the URL | |
return false; | |
} else { | |
// show the proper "not connected" message | |
view.loadData(offlineMessageHtml, "text/html", "utf-8"); | |
// return true if the host application wants to leave the current | |
// WebView and handle the url itself | |
return true; | |
} | |
} | |
@Override | |
public void onReceivedError (WebView view, int errorCode, | |
String description, String failingUrl) { | |
if (errorCode == ERROR_TIMEOUT) { | |
view.stopLoading(); // may not be needed | |
view.loadData(timeoutMessageHtml, "text/html", "utf-8"); | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { | |
mWebView.removeJavascriptInterface("searchBoxJavaBridge_"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment