Example usage for android.net NetworkInfo isAvailable

List of usage examples for android.net NetworkInfo isAvailable

Introduction

In this page you can find the example usage for android.net NetworkInfo isAvailable.

Prototype

@Deprecated
public boolean isAvailable() 

Source Link

Document

Indicates whether network connectivity is possible.

Usage

From source file:com.lee.sdk.utils.Utils.java

/**
 * ??(//from www.jav a2  s . com
 * 
 * @param context context
 * @return ? true
 */
public static boolean isNetworkConnected(Context context) {
    NetworkInfo networkInfo = getActiveNetworkInfo(context);
    // return networkInfo != null && networkInfo.isConnected();
    boolean flag = networkInfo != null && networkInfo.isAvailable();
    return flag;
}

From source file:com.frostwire.android.gui.NetworkManager.java

private boolean isNetworkTypeUp(ConnectivityManager connectivityManager, final int networkType) {
    NetworkInfo networkInfo = connectivityManager.getNetworkInfo(networkType);
    return networkInfo != null && networkInfo.isAvailable() && networkInfo.isConnected();
}

From source file:org.OneEducation.HarvestClient.HarvestReporter.java

public Boolean canReport() {
    Log.d("HarvestReporter", "canReport");

    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = manager.getActiveNetworkInfo();
    if (info == null || !info.isAvailable() || !info.isConnected()) {
        Log.d("HarvestReporter", "canReport: not connected");
        return false;
    }//from  w  w  w  . j  a  v a2  s. c  om

    if ((settings.getRealNowSeconds() - lastAttempt) < HarvestSettings.ATTEMPT_INTERVAL) {
        Log.d("HarvestReporter", "canReport: too soon to try");
        return false;
    }
    if ((settings.getClockNowSeconds() - settings.getLastReported()) < HarvestSettings.REPORT_INTERVAL) {
        Log.d("HarvestReporter", "canReport: too son to report");
        return false;
    }

    if (previousTask != null && previousTask.getStatus() != Status.FINISHED) {
        Log.d("HarvestReporter", "canReport: previous task is still running");
        return false;
    }

    return true;
}

From source file:de.dhbw.organizer.calendar.backend.manager.NetworkManager.java

/**
 * tests if device got any internet connection
 * //from   ww  w.j a v  a2s. c om
 * @return true if availabe, false otherwise
 */
public boolean isOnline() {
    boolean connected = false;
    try {
        connectivityManager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);

        NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
        connected = networkInfo != null && networkInfo.isAvailable() && networkInfo.isConnected();
        return connected;

    } catch (Exception e) {

        Log.e(TAG, "isOnline() ERROR " + e.toString());
    }
    return connected;
}

From source file:com.OpenSource.engine.connectivity.ConnectivityInfoProvider.java

public boolean isAvailable() {
    NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
    return (networkInfo == null) ? false : networkInfo.isAvailable();
}

From source file:com.loadsensing.app.LoginActivity.java

private boolean checkConnection(Context ctx) {
    ConnectivityManager conMgr = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo i = conMgr.getActiveNetworkInfo();
    if (i == null)
        return false;
    if (!i.isConnected())
        return false;
    if (!i.isAvailable())
        return false;
    return true;/*  ww w.  ja  va  2s  . c o  m*/
}

From source file:com.codestation.henkakuserver.MainActivity.java

public boolean isConnectedInWifi(boolean wifiOnly) {
    WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    NetworkInfo networkInfo = ((ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE))
            .getActiveNetworkInfo();//  w  ww .j  a  v a2s. c  o  m
    boolean wifiEnabled = networkInfo != null && networkInfo.isAvailable() && networkInfo.isConnected()
            && wifiManager.isWifiEnabled() && networkInfo.getTypeName().equals("WIFI");

    if (!wifiOnly && !wifiEnabled) {
        try {
            final Method method = wifiManager.getClass().getDeclaredMethod("isWifiApEnabled");
            method.setAccessible(true);
            wifiEnabled = (Boolean) method.invoke(wifiManager);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    return wifiEnabled;
}

From source file:org.mrquiz.android.tinyurl.SendTinyUrlActivity.java

private boolean networkConnected() {
    boolean result = false;
    ConnectivityManager CM = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    if (CM == null) {
        result = false;//from w w  w  .  j  av  a 2  s .  c o m
    } else {
        NetworkInfo info = CM.getActiveNetworkInfo();
        if (info != null && info.isConnected()) {
            if (!info.isAvailable()) {
                result = false;
            } else {
                result = true;
            }
        }
    }
    return result;
}

From source file:edu.cmu.cylab.starslinger.demo.MainActivity.java

public boolean isOnline() {
    boolean connected = false;
    if (mConnectivityManager == null) {
        mConnectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    }//w w w  .jav a2  s  .  c o  m

    NetworkInfo networkInfo = mConnectivityManager.getActiveNetworkInfo();
    connected = networkInfo != null && networkInfo.isAvailable() && networkInfo.isConnected();
    return connected;
}

From source file:com.jackpan.TaiwanpetadoptionApp.HeadpageActivity.java

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);//    
    requestWindowFeature(Window.FEATURE_NO_TITLE);// ?APP
    setContentView(R.layout.activity_headpage);
    ConnectivityManager conManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
    NetworkInfo networInfo = conManager.getActiveNetworkInfo();

    if (networInfo == null || !networInfo.isAvailable()) {
        new AlertDialog.Builder(HeadpageActivity.this).setTitle(getString(R.string.Network_status))
                .setMessage(getString(R.string.no_network)).setCancelable(false)
                .setPositiveButton(getString(R.string.setting), new DialogInterface.OnClickListener() {

                    @Override/*from  w w  w  . j av  a  2 s  .  com*/
                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub
                        Intent settintIntent = new Intent(android.provider.Settings.ACTION_SETTINGS);
                        startActivity(settintIntent);

                    }
                }).setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub
                        HeadpageActivity.this.finish();
                    }
                }).show();

    } else {
        final ProgressDialog progressDialog = ProgressDialog.show(HeadpageActivity.this,
                getString(R.string.Network_in), getString(R.string.waitting));
        final Handler handler = new Handler();
        final Runnable runnable = new Runnable() {

            @Override
            public void run() {
                // TODO Auto-generated method stub
                new AlertDialog.Builder(HeadpageActivity.this);

                progressDialog.dismiss();

            }
        };

        Thread thread = new Thread() {

            @Override
            public void run() {
                try {
                    Thread.sleep(1500);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                handler.post(runnable);
            }
        };
        thread.start();

    }

    final TextView test = (TextView) findViewById(R.id.textView1);
    Timer timer = new Timer();

    TimerTask task = new TimerTask() {
        public void run() {
            runOnUiThread(new Runnable() {
                public void run() {
                    if (change) {
                        change = false;
                        test.setTextColor(Color.TRANSPARENT); // ?
                    } else {
                        change = true;
                        test.setTextColor(Color.DKGRAY);
                    }
                }
            });
        }
    };
    timer.schedule(task, 1, 800); // ?(timer???)

    mHelper = new IabHelper(this, getString(R.string.my_license_key));
    mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
        public void onIabSetupFinished(IabResult result) {
            if (!result.isSuccess()) {

                MySharedPrefernces.saveIsBuyed(HeadpageActivity.this, false);
            } else {

                MySharedPrefernces.saveIsBuyed(HeadpageActivity.this, false);
                mHelper.queryInventoryAsync(mGotInventoryListener);
            }

        }
    });

    GetButtonView();
    setButtonEvent();
    buildGoogleApiClient();

}