I have the following code that checks to see if there is an Internet connection before calling the AsyncTask method, a βTask,β which then extracts information from the Internet. This really really works if the phone is in flight mode or if the phone is not connected to an external wireless Internet, that is, it doesnβt work in its own online store, which comes with a phone plan.
If the phone is connected to an external wireless modem, but the modem is not connected to the Internet, I get power!
if (isOnline()) { new Task().execute(); } else { Toast.makeText(this, "There seems to be no internet access, please try again later!", Toast.LENGTH_LONG).show(); }
and
public boolean isOnline() { ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); if (netInfo != null && netInfo.isConnectedOrConnecting()) { return true; } return false; }
Does anyone have a βproven and trueβ way around this?
Greetings
Mike.
user903601
source share