Back to project page android.bigredsnapshot.
The source code is released under:
MIT License
If you think the Android project android.bigredsnapshot listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package io.evercam.bigredsnapshot.tasks; /*w ww. j a v a 2 s .co m*/ import java.net.InetAddress; import java.net.UnknownHostException; import android.content.Context; import android.net.ConnectivityManager; import android.os.AsyncTask; import android.util.Log; public class CheckInternetTask extends AsyncTask<Void, Void, Boolean> { private Context context; private final String TAG = "bigredsnapshot-CheckInternetTask"; private final String HOSTNAME_GOOGLE = "www.google.com"; public CheckInternetTask(Context context) { this.context = context; } @Override protected Boolean doInBackground(Void... params) { if (hasActiveNetwork()) { return true; } else { return false; } } @Override protected void onPostExecute(Boolean hasNetwork) { super.onPostExecute(hasNetwork); } public boolean hasActiveNetwork() { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivityManager.getActiveNetworkInfo() != null) { try { InetAddress.getByName(HOSTNAME_GOOGLE); return true; } catch (UnknownHostException e) { Log.e(TAG, e.getMessage()); } return false; } else { return false; } } }