我有一个应用程序,有两种类型的“无互联网错误”。
当您启动应用程序时,它会查看您是否有互联网并显示错误无互联网
,并且我的 WebView 中有一个指向自定义页面的loadURL
。
我想隐藏webview网站,但是用自定义页面,需要一点时间,就可以看到错误+网站。
可以满足我的需求吗?
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view=inflater.inflate(R.layout. fragment_paginainicio, container, false);
final WebView mWebView = (WebView) view.findViewById(R.id.webView_websitepage);
mWebView.loadUrl("https://google.pt");
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
mWebView.loadUrl("file:///android_asset/errorpage.html");
}
});
最佳答案
You have to check if internet is available. Below code will help in that case. If it is not available you can simple make webview visiblity to gone or do not load anything and show alert dialog for no network
public static boolean isNetworkAvailable(Context mContext) {
ConnectivityManager connectivityManager
= (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}
关于java - 没有互联网显示对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58460631/