5
Please have a webview on my android app, how can I customize if the user doesn’t have internet ? Thank you
Code of the current webcview :
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");
Code suggested by @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");
}
}
Add the code so the guys can help you. Also enjoy and see [Ask]
– user28595