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.rickendirk.rsgwijzigingen.ZoekService.java

@Override
protected void onHandleIntent(Intent intent) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    boolean clusters_enabled = sp.getBoolean("pref_cluster_enabled", true);
    boolean alleenBijWifi = sp.getBoolean("pref_auto_zoek_wifi", false);
    boolean isAchtergrond = intent.getBooleanExtra("isAchtergrond", false);
    if (alleenBijWifi && isAchtergrond) {
        ConnectivityManager conManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo nwInfo = conManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        if (!nwInfo.isConnectedOrConnecting()) {
            //Later weer proberen: nu geen wifi
            setAlarmIn20Min();// w ww . j a  v  a  2 s.  c  o  m
            return;
        }
    }
    Wijzigingen wijzigingen = checkerNieuw(clusters_enabled);
    //Tracken dat er is gezocht
    OwnApplication application = (OwnApplication) getApplication();
    Tracker tracker = application.getDefaultTracker();

    if (isAchtergrond) {
        tracker.send(
                new HitBuilders.EventBuilder().setCategory("Acties").setAction("Zoeken_achtergrond").build());
        sendNotification(wijzigingen);
    } else {
        tracker.send(
                new HitBuilders.EventBuilder().setCategory("Acties").setAction("Zoeken_voorgrond").build());
        boolean isFoutMelding = wijzigingen.isFoutmelding();
        if (!isFoutMelding)
            wijzigingen.saveToSP(this);
        broadcastResult(wijzigingen, clusters_enabled);
    }
}

From source file:com.therealjoshua.essentials.bitmaploader.BitmapLoader.java

private boolean hasInternet() {
    if (canAccessNetworkState) {
        ConnectivityManager cm = (ConnectivityManager) appContext
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo info = cm.getActiveNetworkInfo();
        if (info != null && info.isConnectedOrConnecting()) {
            return true;
        } else {//w ww. j  a  va 2 s.  co m
            return false;
        }
    } else {
        // if can't access the network state, assume we have internet
        return true;
    }
}

From source file:net.gsantner.opoc.util.ContextUtils.java

/**
 * Get internet connection state - the permission ACCESS_NETWORK_STATE is required
 *
 * @return True if internet connection available
 *///from   w w  w .j  a  v  a  2s  . c o  m
public boolean isConnectedToInternet() {
    try {
        ConnectivityManager con = (ConnectivityManager) _context.getSystemService(Context.CONNECTIVITY_SERVICE);
        @SuppressLint("MissingPermission")
        NetworkInfo activeNetInfo = con == null ? null : con.getActiveNetworkInfo();
        return activeNetInfo != null && activeNetInfo.isConnectedOrConnecting();
    } catch (Exception ignored) {
        throw new RuntimeException("Error: Developer forgot to declare a permission");
    }
}

From source file:com.snt.bt.recon.activities.MainActivity.java

public void syncServerDatabase() {
    //check for connectivity
    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();

    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

    //sync database
    if (isConnected) {
        boolean wifiOnly = sp.getBoolean("preferred_sync", false);
        boolean isWiFi = activeNetwork.getType() == ConnectivityManager.TYPE_WIFI;
        if (!isWiFi && wifiOnly) {
            logDebug("syncServerDatabase",
                    "Phone isConnected - Not Synchronizing upon user request because connection is not WiFi");
        } else {/*from  w  w w.java  2  s.  com*/
            logDebug("syncServerDatabase", "Phone isConnected - Synchronizing");

            syncSQLiteMySQLDB(Trip.class, "tripsJSON", "https://.../api/insert_trip.php");//TODO
            syncSQLiteMySQLDB(GPSLocation.class, "locationsJSON", "https://.../api/insert_locations.php");//TODO
            syncSQLiteMySQLDB(BluetoothClassicEntry.class, "bcJSON", "https://.../api/insert_bc.php");//TODO
            syncSQLiteMySQLDB(BluetoothLowEnergyEntry.class, "bleJSON", "https://.../api/insert_ble.php");//TODO
        }
    } else {
        logDebug("syncServerDatabase", "Phone isNotConnected");

    }
}

From source file:scal.io.liger.LigerDownloadManager.java

private void downloadFromLigerServer() {

    String ligerUrl = Constants.LIGER_URL;
    String ligerObb = ZipHelper.getExpansionZipFilename(context, mainOrPatch, version);

    try {/*from   w w w. j  a v  a  2 s.  c om*/
        // if we're managing the download, download only to the files folder
        // if we're using the google play api, download only to the obb folder
        File ligerPath = new File(ZipHelper.getFileFolderName(context));

        Timber.d("DOWNLOADING " + ligerObb + " FROM " + ligerUrl + " TO " + ligerPath);

        String nameFilter = "";

        if (ligerObb.startsWith(Constants.MAIN)) {
            nameFilter = nameFilter + Constants.MAIN + ".*." + context.getPackageName() + ".*.tmp";
        }
        if (ligerObb.startsWith(Constants.PATCH)) {
            nameFilter = nameFilter + Constants.PATCH + ".*." + context.getPackageName() + ".*.tmp";
        }

        if (nameFilter.length() == 0) {
            Timber.d("CLEANUP: DON'T KNOW HOW TO BUILD WILDCARD FILTER BASED ON " + ligerObb);
        } else {
            Timber.d("CLEANUP: DELETING " + nameFilter + " FROM " + ligerPath.getPath());
        }

        WildcardFileFilter oldFileFilter = new WildcardFileFilter(nameFilter);
        for (File oldFile : FileUtils.listFiles(ligerPath, oldFileFilter, null)) {
            Timber.d("CLEANUP: FOUND " + oldFile.getPath() + ", DELETING");
            FileUtils.deleteQuietly(oldFile);
        }

        File targetFile = new File(ligerPath, ligerObb + ".tmp");

        // if there is no connectivity, do not queue item (no longer seems to pause if connection is unavailable)
        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo ni = cm.getActiveNetworkInfo();

        if ((ni != null) && (ni.isConnectedOrConnecting())) {

            if (context instanceof Activity) {
                // Utility.toastOnUiThread((Activity) context, "Starting download of " + mainOrPatch + " expansion file.", false); // FIXME move to strings
            }

            // check preferences.  will also need to check whether tor is active within method
            SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
            boolean useTor = settings.getBoolean("pusetor", false);
            boolean useManager = settings.getBoolean("pusedownloadmanager", false);

            //if (checkTor(useTor, context)) {
            if (useTor && useManager) {
                Timber.e("ANDROID DOWNLOAD MANAGER IS NOT COMPATABLE WITH TOR");

                if (context instanceof Activity) {
                    Utility.toastOnUiThread((Activity) context,
                            "Check settings, can't use download manager and tor", true); // FIXME move to strings
                }

                QueueManager.checkQueueFinished(context, targetFile.getName());

            } else if (useTor || !useManager) {
                downloadWithTor(useTor, Uri.parse(ligerUrl + ligerObb),
                        mAppTitle + " " + mainOrPatch + " file download", ligerObb, targetFile);
            } else {
                downloadWithManager(Uri.parse(ligerUrl + ligerObb),
                        mAppTitle + " " + mainOrPatch + " file download", ligerObb, Uri.fromFile(targetFile));
            }

        } else {
            Timber.d("NO CONNECTION, NOT QUEUEING DOWNLOAD: " + ligerUrl + ligerObb + " -> "
                    + targetFile.getPath());

            if (context instanceof Activity) {
                Utility.toastOnUiThread((Activity) context,
                        "Check settings, no connection, can't start download", true); // FIXME move to strings
            }

            QueueManager.checkQueueFinished(context, targetFile.getName());

        }

    } catch (Exception e) {
        Timber.e("DOWNLOAD ERROR: " + ligerUrl + ligerObb + " -> " + e.getMessage());
        e.printStackTrace();
    }
}

From source file:com.example.android.recyclingbanks.MainActivity.java

protected void getDataLoaderGoing() {
    Log.i("getDataLoaderGoing", "Loader manager next???");
    ConnectivityManager cm = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();
    if (isConnected) {
        LoaderManager loaderManager = getLoaderManager();
        loaderManager.initLoader(0, null, this);
    } else {//from w w  w  .ja  va  2  s .  co  m
        mProgressBar.setVisibility(View.GONE);
        mSpinnerLayout.setVisibility(View.GONE);
        mEmptyView.setText("No internet connection");
    }
}

From source file:com.chummy.jezebel.material.dark.activities.Main.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    context = this;
    mPrefs = new Preferences(Main.this);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//from  w w  w .j  a  v  a2 s .  c o  m
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    thaApp = getResources().getString(R.string.app_name);
    thaHome = getResources().getString(R.string.section_one);
    thaPreviews = getResources().getString(R.string.section_two);
    thaApply = getResources().getString(R.string.section_three);
    thaWalls = getResources().getString(R.string.section_four);
    thaRequest = getResources().getString(R.string.section_five);
    thaCredits = getResources().getString(R.string.section_seven);
    thaTesters = getResources().getString(R.string.section_eight);
    thaWhatIsThemed = getResources().getString(R.string.section_nine);
    thaContactUs = getResources().getString(R.string.section_ten);
    thaLogcat = getResources().getString(R.string.section_eleven);
    thaFAQ = getResources().getString(R.string.section_twelve);
    thaHelp = getResources().getString(R.string.section_thirteen);
    thaAbout = getResources().getString(R.string.section_fourteen);
    thaIconPack = getResources().getString(R.string.section_fifteen);
    thaFullChangelog = getResources().getString(R.string.section_sixteen);
    thaRebuild = getResources().getString(R.string.section_seventeen);

    drawerVersion = getResources().getString(R.string.version_code);

    currentItem = 1;

    headerResult = new AccountHeader().withActivity(this).withHeaderBackground(R.drawable.header)
            .withSelectionFirstLine(getResources().getString(R.string.app_name))
            .withSelectionSecondLine(drawerVersion).withSavedInstance(savedInstanceState).withHeightDp(120)
            .build();

    enable_features = mPrefs.isFeaturesEnabled();
    firstrun = mPrefs.isFirstRun();

    result = new Drawer().withActivity(this).withToolbar(toolbar).withAccountHeader(headerResult)
            .withHeaderDivider(false).withDrawerWidthDp(400)
            .addDrawerItems(new SectionDrawerItem().withName("Main"),
                    new PrimaryDrawerItem().withName(thaHome).withIcon(GoogleMaterial.Icon.gmd_home)
                            .withIdentifier(1),
                    new PrimaryDrawerItem().withName(thaIconPack)
                            .withIcon(GoogleMaterial.Icon.gmd_picture_in_picture)
                            .withDescription("This applies icon pack 'Whicons'.").withCheckable(false)
                            .withIdentifier(11),
                    new PrimaryDrawerItem().withName(thaFullChangelog)
                            .withIcon(GoogleMaterial.Icon.gmd_wrap_text)
                            .withDescription("Complete changelog of Dark Material.").withCheckable(false)
                            .withIdentifier(12),
                    new DividerDrawerItem(), new SectionDrawerItem().withName("Information"),
                    new PrimaryDrawerItem().withName(thaAbout).withIcon(GoogleMaterial.Icon.gmd_info_outline)
                            .withDescription("Basic information on the theme.").withIdentifier(10),
                    new PrimaryDrawerItem().withName(thaWhatIsThemed).withIcon(GoogleMaterial.Icon.gmd_warning)
                            .withDescription("List of overlaid applications.").withIdentifier(3),
                    new PrimaryDrawerItem().withName(thaFAQ).withIcon(GoogleMaterial.Icon.gmd_question_answer)
                            .withDescription("Common questions with answers.").withIdentifier(8),
                    new DividerDrawerItem(), new SectionDrawerItem().withName("Tools & Utilities"),
                    new PrimaryDrawerItem().withName(thaRebuild).withIcon(GoogleMaterial.Icon.gmd_sync)
                            .withDescription("A rebuild a day keeps the RRs away!").withCheckable(false)
                            .withBadge("ROOT ").withIdentifier(13),
                    new PrimaryDrawerItem().withName(thaLogcat).withIcon(GoogleMaterial.Icon.gmd_bug_report)
                            .withDescription("System level log recording.").withCheckable(false)
                            .withBadge("ROOT ").withIdentifier(7),
                    new DividerDrawerItem(), new SectionDrawerItem().withName("The Developers"),
                    new PrimaryDrawerItem().withName(thaCredits).withIcon(GoogleMaterial.Icon.gmd_people)
                            .withDescription("chummy development team").withIdentifier(5),
                    new PrimaryDrawerItem().withName(thaTesters).withIcon(GoogleMaterial.Icon.gmd_star)
                            .withDescription("The people who keep the team updated.").withIdentifier(4),
                    new DividerDrawerItem(), new SectionDrawerItem().withName("Contact"),
                    new SecondaryDrawerItem().withName(thaContactUs).withIcon(GoogleMaterial.Icon.gmd_mail)
                            .withCheckable(false).withIdentifier(6),
                    new SecondaryDrawerItem().withName(thaHelp).withIcon(GoogleMaterial.Icon.gmd_help)
                            .withCheckable(true).withIdentifier(9))
            .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id,
                        IDrawerItem drawerItem) {

                    if (drawerItem != null) {

                        switch (drawerItem.getIdentifier()) {
                        case 1:
                            switchFragment(1, thaApp, "Home");
                            break;
                        case 2:
                            ConnectivityManager cm = (ConnectivityManager) context
                                    .getSystemService(Context.CONNECTIVITY_SERVICE);
                            NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
                            boolean isConnected = activeNetwork != null
                                    && activeNetwork.isConnectedOrConnecting();

                            if (isConnected) {
                                switchFragment(2, thaWalls, "Wallpapers");
                            } else {
                                showNotConnectedDialog();
                            }
                            break;
                        case 3:
                            switchFragment(3, thaWhatIsThemed, "WhatIsThemed");
                            break;
                        case 4:
                            switchFragment(4, thaTesters, "Testers");
                            break;
                        case 5:
                            switchFragment(5, thaCredits, "Credits");
                            break;
                        case 6:
                            StringBuilder emailBuilder = new StringBuilder();
                            Intent intent = new Intent(Intent.ACTION_VIEW,
                                    Uri.parse("mailto:" + getResources().getString(R.string.email_id)));
                            if (!isAppInstalled("org.cyanogenmod.theme.chooser")) {
                                if (!isAppInstalled("com.cyngn.theme.chooser")) {
                                    if (!isAppInstalled("com.lovejoy777.rroandlayersmanager")) {
                                        intent.putExtra(Intent.EXTRA_SUBJECT,
                                                getResources().getString(R.string.email_subject));
                                    } else {
                                        intent.putExtra(Intent.EXTRA_SUBJECT,
                                                getResources().getString(R.string.email_subject_rro));
                                    }
                                } else {
                                    intent.putExtra(Intent.EXTRA_SUBJECT,
                                            getResources().getString(R.string.email_subject_cos));
                                }
                            } else {
                                intent.putExtra(Intent.EXTRA_SUBJECT,
                                        getResources().getString(R.string.email_subject_cm));
                            }
                            emailBuilder.append("\n \n \nOS Version: " + System.getProperty("os.version") + "("
                                    + Build.VERSION.INCREMENTAL + ")");
                            emailBuilder.append("\nOS API Level: " + Build.VERSION.SDK_INT + " ("
                                    + Build.VERSION.RELEASE + ") " + "[" + Build.ID + "]");
                            emailBuilder.append("\nDevice: " + Build.DEVICE);
                            emailBuilder.append("\nManufacturer: " + Build.MANUFACTURER);
                            emailBuilder.append(
                                    "\nModel (and Product): " + Build.MODEL + " (" + Build.PRODUCT + ")");
                            if (!isAppInstalled("org.cyanogenmod.theme.chooser")) {
                                if (!isAppInstalled("com.cyngn.theme.chooser")) {
                                    if (!isAppInstalled("com.lovejoy777.rroandlayersmanager")) {
                                        emailBuilder.append("\nTheme Engine: Not Available");
                                    } else {
                                        emailBuilder.append("\nTheme Engine: Layers Manager (RRO)");
                                    }
                                } else {
                                    emailBuilder.append("\nTheme Engine: Cyanogen OS Theme Engine");
                                }
                            } else {
                                emailBuilder.append("\nTheme Engine: CyanogenMod Theme Engine");
                            }
                            PackageInfo appInfo = null;
                            try {
                                appInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
                            } catch (PackageManager.NameNotFoundException e) {
                                e.printStackTrace();
                            }
                            emailBuilder.append("\nApp Version Name: " + appInfo.versionName);
                            emailBuilder.append("\nApp Version Code: " + appInfo.versionCode);

                            intent.putExtra(Intent.EXTRA_TEXT, emailBuilder.toString());
                            startActivity(Intent.createChooser(intent,
                                    (getResources().getString(R.string.send_title))));
                            break;
                        case 7:
                            if (Shell.SU.available()) {
                                if (!isAppInstalled("com.tooleap.logcat")) {
                                    if (!isAppInstalled("com.nolanlawson.logcat")) {
                                        Intent logcat = new Intent(Intent.ACTION_VIEW, Uri.parse(
                                                getResources().getString(R.string.play_store_link_logcat)));
                                        startActivity(logcat);
                                    } else {
                                        Intent intent_logcat = getPackageManager()
                                                .getLaunchIntentForPackage("com.nolanlawson.logcat");
                                        Toast toast = Toast.makeText(getApplicationContext(),
                                                getResources().getString(R.string.logcat_toast),
                                                Toast.LENGTH_LONG);
                                        toast.show();
                                        startActivity(intent_logcat);
                                    }
                                } else {
                                    Intent intent_tooleap = getPackageManager()
                                            .getLaunchIntentForPackage("com.tooleap.logcat");
                                    Toast toast = Toast.makeText(getApplicationContext(),
                                            getResources().getString(R.string.logcat_toast), Toast.LENGTH_LONG);
                                    toast.show();
                                    startActivity(intent_tooleap);
                                }
                            } else {
                                Toast toast = Toast.makeText(getApplicationContext(),
                                        "Unfortunately, this feature is only available for root users.",
                                        Toast.LENGTH_LONG);
                                toast.show();
                            }
                            break;
                        case 8:
                            switchFragment(8, thaFAQ, "FAQ");
                            break;
                        case 9:
                            switchFragment(9, thaHelp, "Help");
                            break;
                        case 10:
                            switchFragment(10, thaAbout, "About");
                            break;
                        case 11:
                            Intent launch_whicons = new Intent("android.intent.action.MAIN");
                            launch_whicons.setComponent(new ComponentName("org.cyanogenmod.theme.chooser",
                                    "org.cyanogenmod.theme.chooser.ChooserActivity"));
                            launch_whicons.putExtra("pkgName", "com.whicons.iconpack");
                            Intent launch_whicons_cos = new Intent("android.intent.action.MAIN");
                            launch_whicons_cos.setComponent(new ComponentName("com.cyngn.theme.chooser",
                                    "com.cyngn.theme.chooser.ChooserActivity"));
                            launch_whicons_cos.putExtra("pkgName", "com.whicons.iconpack");
                            Intent devPlay = new Intent(Intent.ACTION_VIEW,
                                    Uri.parse(getResources().getString(R.string.play_store_whicons)));
                            Intent intent_whicons = getPackageManager()
                                    .getLaunchIntentForPackage("com.whicons.iconpack");
                            if (intent_whicons == null) {
                                startActivity(devPlay);
                            } else {
                                if (isAppInstalled("org.cyanogenmod.theme.chooser")) {
                                    startActivity(launch_whicons);
                                } else {
                                    if (isAppInstalled("com.cyngn.theme.chooser")) {
                                        Toast toast = Toast.makeText(getApplicationContext(),
                                                "Select Dark Material, click Customize and locate Default Icons. Then select Whicons and click Apply.",
                                                Toast.LENGTH_LONG);
                                        toast.show();
                                        startActivity(launch_whicons_cos);
                                    } else {
                                        startActivity(intent_whicons);
                                    }
                                }
                            }
                            break;
                        case 12:
                            fullchangelog();
                            break;
                        case 13:
                            if (Shell.SU.available()) {
                                rebuildThemeCache();
                            } else {
                                Toast toast = Toast.makeText(getApplicationContext(),
                                        "Unfortunately, this feature is only available for root users.",
                                        Toast.LENGTH_LONG);
                                toast.show();
                            }
                            break;
                        }
                    }
                }
            }).withSavedInstance(savedInstanceState).build();

    result.getListView().setVerticalScrollBarEnabled(false);

    // Check for permissions first so that we don't have any issues down the road
    int permissionCheck = ContextCompat.checkSelfPermission(getApplicationContext(),
            android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
    if (permissionCheck == PackageManager.PERMISSION_GRANTED) {
        // permission already granted, allow the program to continue running
        runLicenseChecker();
    } else {
        // permission not granted, request it from the user
        ActivityCompat.requestPermissions(this,
                new String[] { android.Manifest.permission.WRITE_EXTERNAL_STORAGE },
                PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE);
    }

    if (savedInstanceState == null) {
        result.setSelectionByIdentifier(1);
    }

}

From source file:org.mixare.MixViewActivity.java

/**
 * Checks whether a network is available or not
 * @return True if connected, false if not
 *///  w w w  .  jav a2  s  .  com
private boolean isNetworkAvailable() {
    ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(
            Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    return activeNetworkInfo != null && activeNetworkInfo.isConnectedOrConnecting();
}

From source file:org.opensilk.music.artwork.ArtworkRequestManagerImpl.java

boolean isOnline(boolean wifiOnly) {

    boolean state = false;

    /* Wi-Fi connection */
    final NetworkInfo wifiNetwork = mConnectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (wifiNetwork != null) {
        state = wifiNetwork.isConnectedOrConnecting();
    }// w  w  w  . j  a  v a2  s  .com

    // Don't bother checking the rest if we are connected or we have opted out of mobile
    if (wifiOnly || state) {
        return state;
    }

    /* Mobile data connection */
    final NetworkInfo mbobileNetwork = mConnectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    if (mbobileNetwork != null) {
        state = mbobileNetwork.isConnectedOrConnecting();
    }

    /* Other networks */
    final NetworkInfo activeNetwork = mConnectivityManager.getActiveNetworkInfo();
    if (activeNetwork != null) {
        state = activeNetwork.isConnectedOrConnecting();
    }

    return state;
}

From source file:com.flipzu.flipzu.Player.java

private boolean isOnline() {
    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    if (netInfo != null && netInfo.isConnectedOrConnecting()) {
        debug.logV(TAG, "isOnline, returning true");
        return true;
    }// ww w .  j a  v a  2s  . c o  m
    debug.logV(TAG, "isOnline, returning false");
    return false;
}