I'm trying to implement Internet check in Android in AsyncTask. I've created a separate class file for this. The aim is to check Internet in doInBackground and return the value to onPostExecute -and show the result in main UI thread. But what must be the context argument for isNetworkAvailable(context)? For now it gives error about argument. Also is it all OK with isNetworkAvailable?
How to use this value in onPostExecute and pass it to the main UI thread?
import android.content.Context;
import android.net.ConnectivityManager;
import android.os.AsyncTask;
class InternetCheck extends AsyncTask<Void, Void, Boolean> {
protected Boolean doInBackground(Void... noargs) {
return isNetworkAvailable(this);
}
protected void onProgressUpdate(Integer... progress) {
}
protected void onPostExecute(String result) {
}
public static boolean isNetworkAvailable(Context context)
{
return ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo() != null;
}
}