Example usage for android.net.wifi WifiManager isWifiEnabled

List of usage examples for android.net.wifi WifiManager isWifiEnabled

Introduction

In this page you can find the example usage for android.net.wifi WifiManager isWifiEnabled.

Prototype

public boolean isWifiEnabled() 

Source Link

Document

Return whether Wi-Fi is enabled or disabled.

Usage

From source file:com.binomed.showtime.android.util.localisation.LocationUtils.java

public static boolean isLocalisationEnabled(Context context, ProviderEnum provider) {
    boolean result = false;
    switch (provider) {
    case GPS_PROVIDER:
    case GSM_PROVIDER: {
        LocationManager locationManager = getLocationManager(context);
        if (locationManager != null) {
            try {
                result = locationManager.isProviderEnabled(provider.getAndroidProvider());
            } catch (Exception e) {
                result = false;//  www.j a  va  2 s .c  o m
            }
        }
        break;
    }
    case XPS_PROVIDER: {
        LocationManager locationManager = getLocationManager(context);
        WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        if ((locationManager != null) && (wm != null)) {
            try {
                result = (locationManager.isProviderEnabled(ProviderEnum.GPS_PROVIDER.getAndroidProvider()) //
                        || locationManager.isProviderEnabled(ProviderEnum.GSM_PROVIDER.getAndroidProvider())) //
                        && wm.isWifiEnabled();
            } catch (Exception e) {
                result = false;
            }
        }
        break;
    }
    case WIFI_PROVIDER: {
        WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        if (wm != null) {
            result = wm.isWifiEnabled();
        }
        break;
    }
    case IP_PROVIDER: {
        result = true;
        break;
    }
    default:
        break;
    }
    return result;
}

From source file:com.zzl.zl_app.cache.Utility.java

public static HttpClient getNewHttpClient(Context context) {
    try {//  w w w.  ja  va 2s .co m
        KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
        trustStore.load(null, null);

        SSLSocketFactory sf = new MySSLSocketFactory(trustStore);
        sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

        HttpParams params = new BasicHttpParams();

        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);

        SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
        registry.register(new Scheme("https", sf, 443));

        ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);
        // Set the default socket timeout (SO_TIMEOUT) // in
        // milliseconds which is the timeout for waiting for data.
        HttpConnectionParams.setConnectionTimeout(params, Utility.SET_CONNECTION_TIMEOUT);
        HttpConnectionParams.setSoTimeout(params, Utility.SET_SOCKET_TIMEOUT);
        HttpClient client = new DefaultHttpClient(ccm, params);

        WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        WifiInfo info = wifiManager.getConnectionInfo();
        if (!wifiManager.isWifiEnabled() || -1 == info.getNetworkId()) {
            // ??APN?
            Uri uri = Uri.parse("content://telephony/carriers/preferapn");
            Cursor mCursor = context.getContentResolver().query(uri, null, null, null, null);
            if (mCursor != null && mCursor.moveToFirst()) {
                // ???
                String proxyStr = mCursor.getString(mCursor.getColumnIndex("proxy"));
                if (proxyStr != null && proxyStr.trim().length() > 0) {
                    HttpHost proxy = new HttpHost(proxyStr, 80);
                    client.getParams().setParameter(ConnRouteParams.DEFAULT_PROXY, proxy);
                }
                mCursor.close();
            }
        }
        return client;
    } catch (Exception e) {
        return new DefaultHttpClient();
    }
}

From source file:com.haoqee.chatsdk.net.Utility.java

/**
 * Get a HttpClient object which is setting correctly .
 * //from   www .j av a2 s . c om
 * @param context
 *            : context of activity
 * @return HttpClient: HttpClient object
 */
public static DefaultHttpClient getHttpClient(Context context) {
    BasicHttpParams httpParameters = new BasicHttpParams();
    // Set the default socket timeout (SO_TIMEOUT) // in
    // milliseconds which is the timeout for waiting for data.
    HttpConnectionParams.setConnectionTimeout(httpParameters, Utility.SET_CONNECTION_TIMEOUT);
    HttpConnectionParams.setSoTimeout(httpParameters, Utility.SET_SOCKET_TIMEOUT);
    DefaultHttpClient client = new DefaultHttpClient(httpParameters);
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    if (!wifiManager.isWifiEnabled()) {
        // ??PN????
        Uri uri = Uri.parse("content://telephony/carriers/preferapn");
        Cursor mCursor = context.getContentResolver().query(uri, null, null, null, null);
        if (mCursor != null && mCursor.moveToFirst()) {
            // ??????
            String proxyStr = mCursor.getString(mCursor.getColumnIndex("proxy"));
            if (proxyStr != null && proxyStr.trim().length() > 0) {
                HttpHost proxy = new HttpHost(proxyStr, 80);
                client.getParams().setParameter(ConnRouteParams.DEFAULT_PROXY, proxy);
            }
            mCursor.close();
        }
    }
    return client;
}

From source file:org.brandroid.openmanager.fragments.DialogHandler.java

public static String getNetworkInfo(Context c) {
    String ret = getNetworkInterfaces();

    ConnectivityManager conman = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (conman == null)
        ret += "No Connectivity?\n";
    else {//  www  .j  ava 2s  .c o m
        ret += "Connectivity Info:\n" + conman.toString() + "\n";
        for (NetworkInfo ni : conman.getAllNetworkInfo()) {
            if (!ni.isAvailable())
                continue;
            ret += "Network [" + ni.getTypeName() + "]: " + getNetworkInfoInfo(ni) + "\n";
        }
    }
    try {
        WifiManager wifi = (WifiManager) c.getSystemService(Context.WIFI_SERVICE);
        if (wifi == null)
            ret += "No wifi\n";
        else {
            ret += "Wifi Info:\n" + wifi.toString() + "\n";
            ret += "Status: " + (wifi.isWifiEnabled() ? "ENABLED" : "DISABLED") + "\n";
            ret += "ip=" + getReadableIP(wifi.getConnectionInfo().getIpAddress()) + "/ " + "mac="
                    + wifi.getConnectionInfo().getMacAddress() + "/ " + "b="
                    + wifi.getConnectionInfo().getBSSID() + "/ " + "s=" + wifi.getConnectionInfo().getSSID();
            DhcpInfo dh = wifi.getDhcpInfo();
            if (dh == null)
                ret += "No DHCP\n";
            else {
                ret += "IP: " + getReadableIP(dh.ipAddress) + "\n";
                ret += "Gateway: " + getReadableIP(dh.gateway) + "\n";
                ret += "DNS: " + getReadableIP(dh.dns1) + " " + getReadableIP(dh.dns2) + "\n";
            }
        }
    } catch (SecurityException sec) {
        ret += "No Wifi permissions.\n";
    }
    return ret;
}

From source file:com.example.qrpoll.Refresh.java

/**
 * sprawdza, czy w urzadzeniu wlaczone jest wifi
 * @return/*from   w  w  w.  ja v a  2s  .  c o  m*/
 */
public boolean checkWifi() {
    WifiManager wifi = (WifiManager) activity.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    return wifi.isWifiEnabled();
}

From source file:org.wahtod.wififixer.ui.LocalNetworksLoader.java

private List<WFScanResult> getNetworks(Context context) {
    WifiManager wm = AsyncWifiManager.getWifiManager(context);

    if (wm.isWifiEnabled()) {
        List<WFScanResult> scanned = WFScanResult.fromScanResultArray(wm.getScanResults());
        if (scanned != null) {
            Collections.sort(scanned, new SortBySignal());
            return scanned;
        }/*ww  w.  j  a v  a2  s.c om*/
    }
    return new ArrayList<WFScanResult>();
}

From source file:com.collectme.cordova.diagnostic.Diagnostic.java

public boolean isWifiEnabled() {
    WifiManager wifiManager = (WifiManager) this.cordova.getActivity().getSystemService(Context.WIFI_SERVICE);
    boolean result = wifiManager.isWifiEnabled();
    return result;
}

From source file:ru.glesik.wifireminders.AlarmService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    if (wifiManager.isWifiEnabled()) {
        Bundle extras = intent.getExtras();
        if (extras == null) { // Service started from AlarmManager - polling.
            // Start networks scan.
            wifiManager.startScan();//from  w w  w .j  a va 2  s.com
        } else { // Service started from BroadcastReceiver - Wi-Fi connected.
            // Check for rules with connected SSID.
            String SSID = (String) extras.get("SSID");
            Log.i("AlarmService", "received SSID " + SSID);
            checkNetworks(SSID);
        }
    } else {
        // Nothing to do.
        stopSelf();
    }
    // We want this service to continue running until it is explicitly
    // stopped, so return sticky.
    return START_STICKY;
}

From source file:com.example.qrpoll.MainActivity.java

/**
 * sprawdzenie stanu wifi//  w  w  w . ja  v a 2  s. co  m
 * @return
 */
public boolean checkWifi() {
    WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    return wifi.isWifiEnabled();
}

From source file:com.zegoggles.smssync.service.ServiceBase.java

@SuppressWarnings("deprecation")
private boolean isConnectedViaWifi_pre_SDK21() {
    WifiManager wifiManager = getWifiManager();
    return (wifiManager != null && wifiManager.isWifiEnabled()
            && getConnectivityManager().getNetworkInfo(TYPE_WIFI) != null
            && getConnectivityManager().getNetworkInfo(TYPE_WIFI).isConnected());
}