Por favor tenho uma webview em meu app android, como poso personalizar caso o user não tenha internet ? Obrigado
Codigo do webcview atual :
WebView wv=(WebView) findViewById(R.id.webView);
WebSettings ws = wv.getSettings();
ws.setJavaScriptEnabled(true);
ws.setSupportZoom(true);
wv.setWebViewClient(new WebViewClient());
wv.loadUrl("http://google.com");
Código sugerido por @PauloRodrigues :
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.net.NetworkInfo;
import android.content.Context;
import android.net.ConnectivityManager;
private class CustomWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (!Functions.isDeviceOnline(context)) {
view.loadUrl("file:///android_asset/no-internet.html");
} else {
view.loadUrl(url);
}
return true;
}
}
public class ConectActivity extends Activity {
public static boolean isDeviceOnline(Context pContext) {
ConnectivityManager cm = (ConnectivityManager) pContext.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
return (netInfo != null && netInfo.isConnectedOrConnecting());
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_conect);
WebView wv=(WebView) findViewById(R.id.webView);
WebSettings ws = wv.getSettings();
ws.setJavaScriptEnabled(true);
ws.setSupportZoom(true); // *** Permite o zoom no webview - Augusto Furlan ***
wv.setWebViewClient(new WebViewClient());
wv.loadUrl("http://www.google.com");
}
}