Главная
>
Android > android webview crash no internet
android webview crash no internet
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
webView = findViewById(R.id.webView);
if(isNetworkConnected(this)){
webView.loadUrl("https://site.ru/");
}
else{
webView.loadUrl("file:///android_asset/lost.html");
}
}
private boolean isNetworkConnected(Context context) {
ConnectivityManager cm =
(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
return activeNetwork != null && activeNetwork.isConnectedOrConnecting();
}
}