Example usage for android.net NetworkInfo isConnectedOrConnecting

List of usage examples for android.net NetworkInfo isConnectedOrConnecting

Introduction

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

Prototype

@Deprecated
public boolean isConnectedOrConnecting() 

Source Link

Document

Indicates whether network connectivity exists or is in the process of being established.

Usage

From source file:com.yattatech.dbtc.activity.GenericFragmentActivity.java

public boolean isConnected() {
    final ConnectivityManager connectivityManager = (ConnectivityManager) getApplicationContext()
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
    return (networkInfo != null) && (networkInfo.isConnectedOrConnecting());
}

From source file:com.adnanbal.fxdedektifi.forex.presentation.services.NotificationService.java

/**
 * Checks if the device has any active internet connection.
 *
 * @return true device with internet connection, otherwise false.
 *///from  w w w.j a v  a 2s  .c o m
private boolean isThereInternetConnection() {
    boolean isConnected;

    ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(
            Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
    isConnected = (networkInfo != null && networkInfo.isConnectedOrConnecting());

    return isConnected;
}

From source file:com.example.android.tabbedroombookingtimetabledisplay.MainFragmentActivity.java

private boolean isNetworkAvailable() {
    ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(
            Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    return activeNetworkInfo != null && activeNetworkInfo.isConnectedOrConnecting();
}

From source file:com.leo.cattle.data.net.RestApiImpl.java

/**
 * Checks if the device has any active internet connection.
 *
 * @return true device with internet connection, otherwise false.
 *///from  w w w  .ja  v a2  s  . com
private boolean isThereInternetConnection() {
    boolean isConnected;

    ConnectivityManager connectivityManager = (ConnectivityManager) this.context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
    isConnected = (networkInfo != null && networkInfo.isConnectedOrConnecting());

    return isConnected;
}

From source file:com.example.droidcodin.popularmdb.MovieFragment.java

public boolean isOnline(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();
    return isConnected;
}

From source file:org.catnut.fragment.TimelineFragment.java

public boolean isNetworkAvailable() {
    NetworkInfo activeNetwork = mConnectivityManager.getActiveNetworkInfo();
    return activeNetwork != null && activeNetwork.isConnectedOrConnecting();
}

From source file:me.ziccard.secureit.async.upload.PeriodicPositionUploaderTask.java

@Override
protected Void doInBackground(Void... params) {

    while (true) {

        Log.i("PeriodicPositionUploaderTask", "Started");

        if (isCancelled()) {
            return null;
        }/*from   ww  w  .j  av a 2s  .c  o  m*/

        HttpClient client = new DefaultHttpClient();

        /*
         * Send the last
         * detected position to /phone/phoneId/position [POST]
         */
        HttpPost request = new HttpPost(Remote.HOST + Remote.PHONES + "/" + phoneId + Remote.UPLOAD_POSITION);

        /*
         * Adding latitude and longitude
         */
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("lat", "" + lat));
        nameValuePairs.add(new BasicNameValuePair("long", "" + lng));
        try {
            request.setEntity(new UrlEncodedFormEntity(nameValuePairs));

            /*
             * Access token
             */
            request.setHeader("access_token", accessToken);

            /*
             * We send position only if Gps/Network fixed
             */

            if (lat != Double.MAX_VALUE && lng != Double.MAX_VALUE) {
                dataSent = true;
                HttpResponse response = client.execute(request);

                BufferedReader reader = new BufferedReader(
                        new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
                StringBuilder builder = new StringBuilder();
                for (String line = null; (line = reader.readLine()) != null;) {
                    builder.append(line).append("\n");
                }

                Log.i("PeriodicPositionUploaderTask", "Response:\n" + builder.toString());

                if (response.getStatusLine().getStatusCode() != 200) {
                    throw new HttpException();
                }
            } else {
                Log.i("PeriodicPositionUploaderTask", "We have no position data yet");
                dataSent = false;
            }
        } catch (Exception e) {
            Log.e("DataUploaderTask", "Error uploading location");
            /*
             * We check if we still have connectivity, if this is not true
             * we start BluetoothPeriodicPositionUploader
             */
            ConnectivityManager cm = (ConnectivityManager) context
                    .getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
            boolean isConnected = activeNetwork.isConnectedOrConnecting();
            if (!isConnected) {
                bluetoothTask = new BluetoothPeriodicPositionUploaderTask(context);
                bluetoothTask.execute();
                locationManager.removeUpdates(this);
                return null;
            }
        }

        try {
            if (dataSent)
                Thread.sleep(3600 * 1000);
            else
                Thread.sleep(60 * 1000);
        } catch (InterruptedException e) {
            return null;
        }
    }
}

From source file:net.sf.aria2.Aria2Service.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (isRunning())
        throw new IllegalStateException("Can not start aria2: running instance already exists!");

    unregisterOldReceiver();//from   ww  w  . ja va 2  s.c om

    final ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
    final NetworkInfo ni = cm.getActiveNetworkInfo();
    if (ni != null && ni.isConnectedOrConnecting())
        startAria2(Config.from(intent));
    else {
        if (intent.hasExtra(Config.EXTRA_INTERACTIVE))
            Toast.makeText(getApplicationContext(), getText(R.string.will_start_later), Toast.LENGTH_LONG)
                    .show();
        else {
            receiver = new BroadcastReceiver() {
                @Override
                public void onReceive(Context context, Intent intent) {
                    if (intent.hasExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY)
                            && intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false))
                        return;

                    startAria2(Config.from(intent));

                    unregisterReceiver(this);
                    receiver = null;
                }
            };

            registerReceiver(receiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
        }
    }

    return super.onStartCommand(intent, flags, startId);
}

From source file:com.appmanager.android.app.DetailActivity.java

private void confirmDownload() {
    FileEntry entry = getFileEntryFromScreen();
    FileEntryValidator validator = new FileEntryValidator(this, entry);
    if (!validator.isValid()) {
        Toast.makeText(this, validator.getErrors(), Toast.LENGTH_SHORT).show();
        return;//from   www .  ja  va  2  s  .  c o  m
    }

    ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = cm.getActiveNetworkInfo();
    if (networkInfo == null || !networkInfo.isConnectedOrConnecting()) {
        Toast.makeText(this, "Not connected to network.", Toast.LENGTH_SHORT).show();
        return;
    }

    if (TextUtils.isEmpty(entry.name)) {
        entry.name = entry.url;
    }

    // Save name and url
    if (mFileEntry == null || mFileEntry.id == 0) {
        // Create
        new FileEntryDao(this).create(entry);
    } else {
        // Update
        new FileEntryDao(this).update(entry);
    }

    Toast.makeText(this, "Installing: " + entry.url, Toast.LENGTH_LONG).show();
    InstallTask task = new InstallTask(this, entry);
    task.setListener(this);
    task.execute(entry.url);
}

From source file:com.senior.javnav.MainActivity.java

private boolean online() {
    ConnectivityManager cm = (ConnectivityManager) getApplicationContext()
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = cm.getActiveNetworkInfo();
    if (info != null && info.isConnectedOrConnecting()) {
        return true;
    } else/*from  w  ww.  j  a va2s.co m*/
        return false;
}