Example usage for android.net.wifi WifiManager WIFI_STATE_ENABLED

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

Introduction

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

Prototype

int WIFI_STATE_ENABLED

To view the source code for android.net.wifi WifiManager WIFI_STATE_ENABLED.

Click Source Link

Document

Wi-Fi is enabled.

Usage

From source file:Main.java

public static boolean isWifiEnabled(WifiManager wifi) {
    return wifi.getWifiState() == WifiManager.WIFI_STATE_ENABLED;
}

From source file:Main.java

public static boolean isWifiEnabledOrEnabling(WifiManager wifi) {
    int wifiState = wifi.getWifiState();
    return wifiState == WifiManager.WIFI_STATE_ENABLED || wifiState == WifiManager.WIFI_STATE_ENABLING;
}

From source file:Main.java

public static boolean isEnabledWifi(Context context) {
    WifiManager wifiMan = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    return null != wifiMan && wifiMan.getWifiState() == WifiManager.WIFI_STATE_ENABLED;
}

From source file:Main.java

public static boolean isWifiEnabled(Context mContext) {
    WifiManager wifi_manager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
    if (wifi_manager != null)
        return (WifiManager.WIFI_STATE_ENABLED == wifi_manager.getWifiState())
                || (WifiManager.WIFI_STATE_ENABLING == wifi_manager.getWifiState());
    return false;
}

From source file:Main.java

public static boolean isWifiEnable(Activity activitiy) {

    WifiManager wm = (WifiManager) activitiy.getSystemService(Context.WIFI_SERVICE);

    return wm.getWifiState() == WifiManager.WIFI_STATE_ENABLED;

}

From source file:Main.java

public static boolean isWifiEnable(Context context) {
    WifiManager mgr = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    if (mgr == null)
        return false;
    int state = mgr.getWifiState();
    return state == WifiManager.WIFI_STATE_ENABLED || state == WifiManager.WIFI_STATE_ENABLING;
}

From source file:Main.java

public static void toggleWifi(Context context) {
    WifiManager wifi_manager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    if (wifi_manager != null) {
        switch (wifi_manager.getWifiState()) {
        case WifiManager.WIFI_STATE_DISABLED:
            wifi_manager.setWifiEnabled(true);
            break;
        case WifiManager.WIFI_STATE_ENABLED:
            wifi_manager.setWifiEnabled(false);
            break;
        }// w w w  .  j  av a2s. c o  m
    }
}

From source file:Main.java

/**
 * Determines if the device's wifi is currently enabled or not.
 * //w  ww  .  j av a  2s.  c o  m
 * @param context A context with which to access wifi system service
 * @return True if wifi is enabled or enabling, false otherwise
 */
public static boolean wifiIsEnabled(ContextWrapper context) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    int wifiState = wifiManager.getWifiState();
    return (wifiState == WifiManager.WIFI_STATE_ENABLED || wifiState == WifiManager.WIFI_STATE_ENABLING);
}

From source file:com.ultrafunk.network_info.receiver.WifiStatusReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    final String action = intent.getAction();

    //   Log.e(this.getClass().getSimpleName(), "onReceive(): " + action);

    updateWifiViews = true;//  w ww.  j  ava 2s  .c o m

    wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    wifiState = wifiManager.getWifiState();
    wifiInfo = wifiManager.getConnectionInfo();

    if ((wifiState == WifiManager.WIFI_STATE_ENABLED) && (wifiInfo.getIpAddress() == 0))
        detailedState = WifiInfo.getDetailedStateOf(wifiInfo.getSupplicantState());

    if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) {
        if (isConnectionReady(intent)) {
            String securityString = WifiUtils.getSecurityString(context, wifiManager, wifiInfo.getBSSID());
            NetworkStateService.setWifiSecurityString(securityString);
            detailsString = context.getString(R.string.security) + ": " + securityString;

            Intent serviceIntent = new Intent(context, NetworkStateService.class);
            serviceIntent.setAction(Constants.ACTION_WIFI_CONNECTED);
            context.startService(serviceIntent);
        }

        partiallyUpdateWidgets(context);
    } else if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)
            || Constants.ACTION_WIFI_SCANNING.equals(action)) {
        partiallyUpdateWidgets(context);
    } else if (Intent.ACTION_SCREEN_ON.equals(action) || Constants.ACTION_WIFI_LINK_SPEED.equals(action)) {
        if (isConnected()) {
            setDetailsString(context);
            partiallyUpdateWidgets(context);
        }
    } else if (Constants.ACTION_UPDATE_WIDGET.equals(action)) {
        if (isConnected())
            setDetailsString(context);

        partiallyUpdateWidget(context, AppWidgetManager.getInstance(context),
                intent.getIntExtra(Constants.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID));
    }
}

From source file:org.geometerplus.fbreader.plugin.local_opds_scanner.ScanLocalNetworkActivity.java

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    setContentView(R.layout.scan_local_network);

    setListAdapter(new ItemAdapter());

    setTitle(R.string.scan_local_network_window_title);

    final View buttonView = findViewById(R.id.scan_local_network_buttons);

    final Button cancelButton = (Button) buttonView.findViewById(R.id.cancel_button);
    cancelButton.setText(R.string.button_cancel);
    cancelButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            finish();//from  w w w  .j a v  a  2 s.  c o m
        }
    });

    final WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    final int state = wifiManager.getWifiState();
    if (state != WifiManager.WIFI_STATE_ENABLED && state != WifiManager.WIFI_STATE_ENABLING) {
        setTitle(R.string.wifi_is_turned_off);
        final View listView = findViewById(android.R.id.list);
        final TextView errorView = (TextView) findViewById(R.id.scan_local_network_error);
        listView.setVisibility(View.GONE);
        errorView.setVisibility(View.VISIBLE);
        errorView.setText(R.string.turn_wifi_on);

        final Button turnOnButton = (Button) buttonView.findViewById(R.id.ok_button);
        turnOnButton.setText(R.string.button_turn_on);
        turnOnButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                wifiManager.setWifiEnabled(true);
                finish();
            }
        });

        myLock = null;
    } else {
        final Button rescanButton = (Button) buttonView.findViewById(R.id.ok_button);
        rescanButton.setText(R.string.button_rescan);
        rescanButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                runOnUiThread(new Runnable() {
                    public void run() {
                        clear();
                        scan();
                    }
                });
            }
        });

        myLock = wifiManager.createMulticastLock("FBReader_lock");
        myLock.setReferenceCounted(true);
        myLock.acquire();

        scan();
    }
}