2
I’m with a project that uses internet, and when there is no internet the same does not leave the menu because I put a lock access to other activit when there is no internet, but in did not open I wanted to play to another specific Action, I can even open a random blank page but the page I request to open does not come, I need help
MENU CODE
public class TRABALHAR extends AppCompatActivity {
private WebView xp4;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_trabalhar);
if(!isOnline()){
startActivity(new Intent(TRABALHAR.this,NOTICIAS2.class));
finish();
}// verifica conexao com a net
xp4 = findViewById(R.id.xp4);
xp4.getSettings().setJavaScriptEnabled(true);
xp4.setWebViewClient(new WebViewClient());
xp4.loadUrl("https://clubcooeec1.blogspot.com/p/fazer-parte-da-equipe.html");
}
public boolean isOnline() {
ConnectivityManager cm = (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
return netInfo != null && netInfo.isConnected(); // verifica se tem internet
}
if I take the line
startActivity(new Intent(WORK.this,NOTICIAS2.class));
the application just blocks access to page, but this is not my goal
how I should proceed in this case ?
your isOnline method does not check internet connection, just check if the user is with any active internet network(wifi, mobile network...). Now to understand better, when there is no internet, do you want to open another acitivity? By your code is not opening? To me it seems normal.
– Murillo Comino
Tried to put the part of this webview into Else??
– Murillo Comino
When I run the code without wifi connected the same opens a White screen less the Activity that I want, in Activity that I want will appear that the same is without connection, mass if you have an applicable code that makes actually check the internet and warn the user already help .
– renan silva das neves
Hello Renan, I tried to detail the answer well, for me it worked well, and with the Asynctask I put it takes the margin of error for when a user is connected wifi or mobile network, but the internet is oscillating or very low and it is not possible to load the url. Give feedback if it goes right or wrong. Abç
– Murillo Comino