Example usage for android.net ConnectivityManager TYPE_WIFI

List of usage examples for android.net ConnectivityManager TYPE_WIFI

Introduction

In this page you can find the example usage for android.net ConnectivityManager TYPE_WIFI.

Prototype

int TYPE_WIFI

To view the source code for android.net ConnectivityManager TYPE_WIFI.

Click Source Link

Document

A WIFI data connection.

Usage

From source file:free.yhc.netmbuddy.utils.Utils.java

/**
 * Is any available active network at this device?
 * @return//w w w  . ja va 2 s .  c o m
 */
public static boolean isNetworkAvailable() {

    ConnectivityManager cm = (ConnectivityManager) getAppContext()
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo ni;

    if (isPrefUseWifiOnly())
        ni = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    else
        ni = cm.getActiveNetworkInfo();

    if (null != ni)
        return ni.isConnectedOrConnecting();
    else
        return false;
}

From source file:com.appnexus.opensdk.AdRequest.java

private AdRequest(AdRequester adRequester, int httpRetriesLeft, int blankRetriesLeft) {
    owner = adRequester.getOwner();/*from  w ww  .  j  av  a 2 s  .co  m*/
    this.requester = adRequester;
    this.httpRetriesLeft = httpRetriesLeft;
    this.blankRetriesLeft = blankRetriesLeft;
    this.placementId = owner.getPlacementID();
    context = owner.getContext();
    String aid = android.provider.Settings.Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);

    // Do we have access to location?
    if (context.checkCallingOrSelfPermission(
            "android.permission.ACCESS_FINE_LOCATION") == PackageManager.PERMISSION_GRANTED
            || context.checkCallingOrSelfPermission(
                    "android.permission.ACCESS_COARSE_LOCATION") == PackageManager.PERMISSION_GRANTED) {
        // Get lat, long from any GPS information that might be currently
        // available
        LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
        Location lastLocation = lm.getLastKnownLocation(lm.getBestProvider(new Criteria(), false));
        if (lastLocation != null) {
            lat = "" + lastLocation.getLatitude();
            lon = "" + lastLocation.getLongitude();
            locDataAge = "" + (System.currentTimeMillis() - lastLocation.getTime());
            locDataPrecision = "" + lastLocation.getAccuracy();
        }
    } else {
        Clog.w(Clog.baseLogTag, Clog.getString(R.string.permissions_missing_location));
    }

    // Do we have permission ACCESS_NETWORK_STATE?
    if (context.checkCallingOrSelfPermission(
            "android.permission.ACCESS_NETWORK_STATE") != PackageManager.PERMISSION_GRANTED) {
        Clog.e(Clog.baseLogTag, Clog.getString(R.string.permissions_missing_network_state));
        fail();
        this.cancel(true);
        return;
    }

    // Get orientation, the current rotation of the device
    orientation = context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE
            ? "h"
            : "v";
    // Get hidmd5, hidsha1, the device ID hashed
    if (Settings.getSettings().hidmd5 == null) {
        Settings.getSettings().hidmd5 = HashingFunctions.md5(aid);
    }
    hidmd5 = Settings.getSettings().hidmd5;
    if (Settings.getSettings().hidsha1 == null) {
        Settings.getSettings().hidsha1 = HashingFunctions.sha1(aid);
    }
    hidsha1 = Settings.getSettings().hidsha1;
    // Get devMake, devModel, the Make and Model of the current device
    devMake = Settings.getSettings().deviceMake;
    devModel = Settings.getSettings().deviceModel;
    // Get carrier
    if (Settings.getSettings().carrierName == null) {
        Settings.getSettings().carrierName = ((TelephonyManager) context
                .getSystemService(Context.TELEPHONY_SERVICE)).getNetworkOperatorName();
    }
    carrier = Settings.getSettings().carrierName;
    // Get firstlaunch and convert it to a string
    firstlaunch = Settings.getSettings().first_launch;
    // Get ua, the user agent...
    ua = Settings.getSettings().ua;
    // Get wxh

    if (owner.isBanner()) {
        this.width = ((BannerAdView) owner).getAdWidth();
        this.height = ((BannerAdView) owner).getAdHeight();
    }

    maxHeight = owner.getContainerHeight();
    maxWidth = owner.getContainerWidth();

    if (Settings.getSettings().mcc == null || Settings.getSettings().mnc == null) {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        String networkOperator = tm.getNetworkOperator();
        if (networkOperator != null && networkOperator.length() >= 6) {
            Settings.getSettings().mcc = networkOperator.substring(0, 3);
            Settings.getSettings().mnc = networkOperator.substring(3);
        }
    }
    mcc = Settings.getSettings().mcc;
    mnc = Settings.getSettings().mnc;

    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo wifi = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    connection_type = wifi.isConnected() ? "wifi" : "wan";
    dev_time = "" + System.currentTimeMillis();

    if (owner instanceof InterstitialAdView) {
        // Make string for allowed_sizes
        allowedSizes = "";
        ArrayList<Size> sizes = ((InterstitialAdView) owner).getAllowedSizes();
        for (Size s : sizes) {
            allowedSizes += "" + s.width() + "x" + s.height();
            // If not last size, add a comma
            if (sizes.indexOf(s) != sizes.size() - 1)
                allowedSizes += ",";
        }
    }

    nativeBrowser = owner.getOpensNativeBrowser() ? "1" : "0";

    //Reserve price
    reserve = owner.getReserve();
    if (reserve <= 0) {
        this.psa = owner.shouldServePSAs ? "1" : "0";
    } else {
        this.psa = "0";
    }

    age = owner.getAge();
    if (owner.getGender() != null) {
        if (owner.getGender() == AdView.GENDER.MALE) {
            gender = "m";
        } else if (owner.getGender() == AdView.GENDER.FEMALE) {
            gender = "f";
        } else {
            gender = null;
        }
    }
    customKeywords = owner.getCustomKeywords();

    mcc = Settings.getSettings().mcc;
    mnc = Settings.getSettings().mnc;
    language = Settings.getSettings().language;
}

From source file:com.matze5800.paupdater.Functions.java

public static boolean WifiConnected(Context context) {
    ConnectivityManager connManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    return mWifi.isConnected();
}

From source file:mobile.tiis.appv2.LoginActivity.java

/**
 * function to check if there is an internet connectivity
 *//*from   ww  w . j a  v  a  2s .  c om*/
public boolean isInternetAvailable() {
    ConnectivityManager cm = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo wifiNetwork = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (wifiNetwork != null && wifiNetwork.isConnected()) {
        return true;
    }
    NetworkInfo mobileNetwork = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    if (mobileNetwork != null && mobileNetwork.isConnected()) {
        return true;
    }
    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    if (activeNetwork != null && activeNetwork.isConnected()) {
        return true;
    }
    return false;
}

From source file:com.mobilyzer.util.PhoneUtils.java

/** Returns the network that the phone is on (e.g. Wifi, Edge, GPRS, etc). */
public String getNetwork() {
    initNetwork();//  www  .j  a va 2s .c o m
    NetworkInfo networkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (networkInfo != null && networkInfo.getState() == NetworkInfo.State.CONNECTED) {
        Logger.d("Current Network: WIFI");
        return NETWORK_WIFI;
    } else {
        return getTelephonyNetworkType();
    }
}

From source file:org.pidome.client.phone.services.SystemService.java

private void setHome() {
    if (prefs != null) {
        if (prefs.getBoolPreference("wifiConnectHomeEnabled", false)) {
            ConnectivityManager connManager = (ConnectivityManager) getSystemService(
                    Context.CONNECTIVITY_SERVICE);
            NetworkInfo networkInfo = connManager.getActiveNetworkInfo();
            if (networkInfo.isConnected() && networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
                final WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
                final WifiInfo connectionInfo = wifiManager.getConnectionInfo();
                if (connectionInfo != null) {
                    String SSID = connectionInfo.getSSID();
                    String BSSID = connectionInfo.getBSSID();
                    if (SSID != null && BSSID != null) {
                        if (SSID.equals(prefs.getStringPreference("wifiConnectSSID",
                                java.util.UUID.randomUUID().toString()))
                                && BSSID.equals(prefs.getStringPreference("wifiConnectBSSID",
                                        java.util.UUID.randomUUID().toString()))) {
                            if (this.system != null) {
                                try {
                                    system.getClient().getEntities().getPresenceService().setPresence(1);
                                } catch (EntityNotAvailableException ex) {
                                    Logger.getLogger(SystemService.class.getName()).log(Level.SEVERE, null, ex);
                                }// w  w  w.  j ava2s  . c  o m
                            }
                        }
                    }
                }
            }
        }
    }
}

From source file:com.kaixin.connect.Util.java

/**
 * Httpapn//from w  w w .  j  av a2s.co  m
 * 
 * @throws IOException
 */
public static HttpURLConnection getConnection(Context context, URL url) throws IOException {

    // WIFIWIFI
    HttpsURLConnection httpsURLConn = null;

    // 
    ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = connMgr.getActiveNetworkInfo();

    // WIFI
    if (null != netInfo && ConnectivityManager.TYPE_WIFI == netInfo.getType()) {
        httpsURLConn = (HttpsURLConnection) url.openConnection();
    } else {// WIFI
        String proxyHost = android.net.Proxy.getDefaultHost();

        if (null == proxyHost) { // 
            httpsURLConn = (HttpsURLConnection) url.openConnection();
        } else { // 
            java.net.Proxy p = new java.net.Proxy(java.net.Proxy.Type.HTTP, new InetSocketAddress(
                    android.net.Proxy.getDefaultHost(), android.net.Proxy.getDefaultPort()));
            httpsURLConn = (HttpsURLConnection) url.openConnection(p);
        }
    }
    return httpsURLConn;
}

From source file:com.inovex.zabbixmobile.push.NotificationService.java

private void logNotification(String status, String message, Long triggerid, String source) {
    // Logging incoming notifications for Debuggin
    // timestamp status message triggerid network
    try {// w ww  .  j a va2 s .  co  m
        File folder = new File(Environment.getExternalStorageDirectory() + "/zax");
        boolean var = false;
        if (!folder.exists()) {
            var = folder.mkdir();
        }
        final String filename = folder.toString() + "/" + "push_logs.csv";
        File csv = new File(filename);
        if (!csv.exists() || !csv.isFile()) {
            csv.createNewFile();
        }
        FileWriter fw = new FileWriter(csv, true);
        String date = Calendar.getInstance().getTime().toString();
        fw.append(date);
        fw.append('\t');
        fw.append(source);
        fw.append('\t');
        fw.append(Long.toString(triggerid));
        fw.append('\t');
        fw.append(status);
        fw.append('\t');
        fw.append(message);
        fw.append('\t');

        ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
        NetworkInfo activeNetwork = cm.getActiveNetworkInfo();

        String net = null;
        switch (activeNetwork.getType()) {
        case ConnectivityManager.TYPE_WIFI:
            String ssid = ((WifiManager) getSystemService(WIFI_SERVICE)).getConnectionInfo().getSSID();
            net = "wifi - ssid: " + ssid;
            break;
        case ConnectivityManager.TYPE_MOBILE:
            net = "mobile";
            break;
        default:
            net = "other network type";
        }
        fw.append(net);
        fw.append("\t\n");
        fw.flush();
        fw.close();
        Log.d(TAG, "writing to logfile " + date + "" + source + " " + status + " " + message + " " + net);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.google.plus.samples.photohunt.ThemeViewActivity.java

private void startCameraIntent() {
    ConnectivityManager connManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
    NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (!mWifi.isConnected()) {
        Toast.makeText(this, getString(R.string.toast_connect_wifi), Toast.LENGTH_LONG).show();
    }//from   w ww  .  ja  va 2s . c  o  m

    Intent cameraIntent = Intents.getCameraIntent();
    startActivityForResult(cameraIntent, REQUEST_CODE_IMAGE_CAPTURE);
}

From source file:com.just.agentweb.AgentWebUtils.java

public static boolean checkWifi(Context context) {
    ConnectivityManager connectivity = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivity == null) {
        return false;
    }//from www  . j a  va 2s . c  o m
    @SuppressLint("MissingPermission")
    NetworkInfo info = connectivity.getActiveNetworkInfo();
    return info != null && info.isConnected() && info.getType() == ConnectivityManager.TYPE_WIFI;
}