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:test.microsoft.com.wifipairing.WifiBase.java

public boolean Start() {

    boolean ret = false;
    //just making sure that when we start we have the Wifi on,
    // after this point we'll respect if it is turned off
    WifiManager wifiManager = (WifiManager) this.context.getSystemService(Context.WIFI_SERVICE);
    if (!wifiManager.isWifiEnabled()) {
        wifiManager.setWifiEnabled(true);
    }/*from   ww w  .  java2  s.  co m*/

    p2p = (WifiP2pManager) this.context.getSystemService(Context.WIFI_P2P_SERVICE);

    if (p2p == null) {
        Log.d("WifiBase", "This device does not support Wi-Fi Direct");
    } else {
        ret = true;
        channel = p2p.initialize(this.context, this.context.getMainLooper(), this);
    }

    mBRReceiver = new MainBCReceiver();
    filter = new IntentFilter();
    filter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION);
    LocalBroadcastManager.getInstance(this.context).registerReceiver((mBRReceiver), filter);

    return ret;
}

From source file:com.amazonaws.devicefarm.android.referenceapp.Fragments.FixturesFragment.java

/**
 * Updates the Wifi status/* www.ja va2s.  c  o  m*/
 */
private void updateWifiStatusDisplay() {
    final WifiManager wifiManager = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE);
    wifi.setText(Boolean.toString(wifiManager.isWifiEnabled()));
}

From source file:test.microsoft.com.wifipairing.WifiBase.java

public boolean isWifiEnabled() {
    WifiManager wifiManager = (WifiManager) this.context.getSystemService(Context.WIFI_SERVICE);
    if (wifiManager != null) {
        return wifiManager.isWifiEnabled();
    } else {/*  w ww  .  j  a v a  2 s  .c  o m*/
        return false;
    }
}

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

protected void onResume() {
    super.onResume();
    // Creating adapter to populate spinnerSSID items.
    adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    Spinner Items = (Spinner) findViewById(R.id.spinnerSSID);
    Items.setAdapter(adapter);//  w w w  .  j  av a  2s.  c  o m
    WifiManager mainWifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    // Start scanning for visible networks.
    if (mainWifi.isWifiEnabled()) {
        mainWifi.startScan();
        // Getting list of stored networks.
        List<WifiConfiguration> wifiList = mainWifi.getConfiguredNetworks();
        for (WifiConfiguration result : wifiList) {
            // Removing quotes.
            adapter.add(result.SSID.toString().replaceAll("^\"|\"$", ""));
        }
        adapter.notifyDataSetChanged();
    } else {
        new AlertDialog.Builder(this).setTitle(R.string.error_wifi_off_title)
                .setMessage(R.string.error_wifi_off_text)
                .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        startActivity(new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK));
                        finish();
                    }
                }).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        finish();
                    }
                }).setIcon(android.R.drawable.ic_dialog_alert).show();
    }
}

From source file:com.mstar.tv.tvplayer.philips.option.OptionFirstFragment.java

private boolean isWifiOpen() {
    WifiManager wifiManager = getWifiManager();
    // wifi is disabled
    if (wifiManager.isWifiEnabled()) {
        return true;
    }/*  ww w .  j a v  a  2 s  .com*/
    return false;
}

From source file:com.mstar.tv.tvplayer.philips.option.OptionFirstFragment.java

private boolean isWifiConnected() {
    WifiManager wifiManager = getWifiManager();
    // wifi is disabled
    if (!wifiManager.isWifiEnabled()) {
        return false;
    }//from  ww w . j a  v  a2  s .  co  m

    // wifi have not connected
    WifiInfo info = wifiManager.getConnectionInfo();
    if (info == null || info.getSSID() == null || info.getNetworkId() == WifiConfiguration.INVALID_NETWORK_ID) {
        return false;
    }

    return true;
}

From source file:net.olejon.spotcommander.MyTools.java

public String getCurrentNetwork() {
    final WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);

    if (wifiManager.isWifiEnabled())
        return wifiManager.getConnectionInfo().getSSID();

    return "";
}

From source file:com.drinviewer.droiddrinviewer.DrinViewerBroadcastReceiver.java

private String getWiFiBroadcastAddress(Context context) {
    String bcastaddr = null;//w  w  w. j  ava  2s.  c o  m
    WifiManager mWifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    DhcpInfo dhcp = mWifi.getDhcpInfo();

    if (mWifi.isWifiEnabled() && dhcp != null) {
        int broadcast = (dhcp.ipAddress & dhcp.netmask) | ~dhcp.netmask;
        byte[] quads = new byte[4];
        for (int k = 0; k < 4; k++)
            quads[k] = (byte) ((broadcast >> k * 8) & 0xFF);

        try {
            bcastaddr = InetAddress.getByAddress(quads).getHostAddress();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
    }
    return bcastaddr;
}

From source file:org.openremote.android.test.console.net.ORNetworkCheckTest.java

private void enableWifi(boolean enable) {

    WifiManager wifi = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE);

    if (enable && wifi.isWifiEnabled())
        return;//from w  w  w.j  a v  a  2s  .c om

    if (!enable && !wifi.isWifiEnabled())
        return;

    if (enable && !wifi.isWifiEnabled()) {
        if (!wifi.setWifiEnabled(true))
            fail("Cannot enable WiFi");
    } else {
        wifi.disconnect();
        wifi.setWifiEnabled(false);
    }

    // wait for it...

    for (int iterations = 0; iterations < 10; iterations++) {
        SystemClock.sleep(500);

        if (enable && wifi.isWifiEnabled())
            break;
        if (!enable && !wifi.isWifiEnabled())
            break;
    }
}

From source file:org.deviceconnect.android.deviceplugin.hue.activity.fragment.HueFragment01.java

/**
 * Wi-Fi?????.//  ww w .  j  a v  a  2s  . com
 * @return true?????????
 */
private boolean isWifiEnabled() {
    WifiManager mgr = (WifiManager) getActivity().getApplicationContext()
            .getSystemService(Context.WIFI_SERVICE);
    return mgr.isWifiEnabled();
}