Android Open Source - android.bigredsnapshot Check Internet Task






From Project

Back to project page android.bigredsnapshot.

License

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.

Java Source Code

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;
    }
  }
}




Java Source Code List

io.evercam.bigredsnapshot.BigButtonActivity.java
io.evercam.bigredsnapshot.BigRedSnapshot.java
io.evercam.bigredsnapshot.ChooseCameraActivity.java
io.evercam.bigredsnapshot.LoginActivity.java
io.evercam.bigredsnapshot.SignUpActivity.java
io.evercam.bigredsnapshot.SlideActivity.java
io.evercam.bigredsnapshot.SnapshotRequest.java
io.evercam.bigredsnapshot.UrlStatus.java
io.evercam.bigredsnapshot.account.AccountUtils.java
io.evercam.bigredsnapshot.account.ProfileQuery.java
io.evercam.bigredsnapshot.account.UserProfile.java
io.evercam.bigredsnapshot.helper.CustomedDialog.java
io.evercam.bigredsnapshot.helper.PrefsManager.java
io.evercam.bigredsnapshot.helper.PropertyReader.java
io.evercam.bigredsnapshot.tasks.CaptureSnapshotTask.java
io.evercam.bigredsnapshot.tasks.CheckInternetTask.java