Example usage for android.net.wifi WifiManager WIFI_STATE_ENABLING

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

Introduction

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

Prototype

int WIFI_STATE_ENABLING

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

Click Source Link

Document

Wi-Fi is currently being enabled.

Usage

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 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(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

/**
 * Determines if the device's wifi is currently enabled or not.
 * /*from w  w w.  j a  va  2 s.co  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: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();//  www.j  a va  2s  . 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();
    }
}

From source file:com.piusvelte.wapdroid.StatusFragment.java

public void setWifiState(int state, String ssid, String bssid) {
    if (state == WifiManager.WIFI_STATE_ENABLED) {
        if (ssid != null) {
            mWifiState.setText(ssid);//from   w ww  .  j a  v  a  2s .c om
            mWifiBSSID.setText(bssid);
        } else {
            mWifiState.setText(getString(R.string.label_enabled));
            mWifiBSSID.setText("");
        }
    } else if (state != WifiManager.WIFI_STATE_UNKNOWN) {
        mWifiState.setText((state == WifiManager.WIFI_STATE_ENABLING ? getString(R.string.label_enabling)
                : (state == WifiManager.WIFI_STATE_DISABLING ? getString(R.string.label_disabling)
                        : getString(R.string.label_disabled))));
        mWifiBSSID.setText("");
    }
}

From source file:org.exobel.routerkeygen.ui.NetworksListActivity.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override/*from  ww  w .  j a va 2 s. co m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_networks_list);

    networkListFragment = ((NetworksListFragment) getFragmentManager()
            .findFragmentById(R.id.frag_networks_list));
    if (findViewById(R.id.keygen_fragment) != null) {
        mTwoPane = true;
        networkListFragment.setActivateOnItemClick(true);
    }
    wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);

    wifiState = wifi.getWifiState() == WifiManager.WIFI_STATE_ENABLED
            || wifi.getWifiState() == WifiManager.WIFI_STATE_ENABLING;
    scanFinished = new WifiScanReceiver(wifi, networkListFragment, this);
    stateChanged = new WifiStateReceiver(wifi, networkListFragment);

    final SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    welcomeScreenShown = mPrefs.getBoolean(Preferences.VERSION, false);

    final long timePassed = System.currentTimeMillis() - mPrefs.getLong(LAST_DIALOG_TIME, 0);
    if (!welcomeScreenShown || (timePassed > DateUtils.WEEK_IN_MILLIS)) {
        final SharedPreferences.Editor editor = mPrefs.edit();
        editor.putBoolean(Preferences.VERSION, true);
        editor.putLong(LAST_DIALOG_TIME, System.currentTimeMillis());
        editor.apply();

        // Checking for updates every week
        if (BuildConfig.APPLICATION_ID.equals("org.exobel.routerkeygen")) {
            startService(new Intent(getApplicationContext(), UpdateCheckerService.class));
        }
        //
    }

    mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swiperefresh);
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            scan();
        }
    });
    mSwipeRefreshLayout.setColorSchemeResources(R.color.accent);
}

From source file:org.exobel.routerkeygen.ui.NetworksListActivity.java

private void scan() {
    if (!wifiState && !wifiOn) {
        networkListFragment.setMessage(R.string.msg_nowifi);
        return;/*from  www .  j  a  v  a 2  s  . co  m*/
    }
    registerReceiver(scanFinished, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
    if (wifi.getWifiState() == WifiManager.WIFI_STATE_ENABLING) {
        registerReceiver(stateChanged, new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION));
        Toast.makeText(this, R.string.msg_wifienabling, Toast.LENGTH_SHORT).show();
    } else {
        if (wifi.startScan()) {
            //setRefreshActionItemState(true);
            mSwipeRefreshLayout.setRefreshing(true);
        } else
            networkListFragment.setMessage(R.string.msg_scanfailed);
    }
}

From source file:org.servDroid.server.service.ServerService.java

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

    wifiStateChangedReceiver = new BroadcastReceiver() {

        @Override//from ww  w  . jav a 2 s .c  om
        public void onReceive(Context context, Intent intent) {
            int extraWifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,
                    WifiManager.WIFI_STATE_UNKNOWN);

            switch (extraWifiState) {
            case WifiManager.WIFI_STATE_DISABLED:
                // Logger.d(TAG, "WIFI STATE DISABLED");
                break;
            case WifiManager.WIFI_STATE_DISABLING:
                if (mPreferenceHelper.isAutostopWifiEnabled() && getServerStatus() == STATUS_RUNNING) {
                    addLog("", "", "", "Wifi connection down... Stopping server");
                    stopServer();
                }
                break;
            case WifiManager.WIFI_STATE_ENABLED:
                // Logger.d(TAG, "WIFI STATE ENABLED");
                break;
            case WifiManager.WIFI_STATE_ENABLING:
                // Logger.d(TAG, "WIFI STATE ENABLING");
                break;
            case WifiManager.WIFI_STATE_UNKNOWN:
                // Logger.d(TAG, "WIFI STATE UNKNOWN");
                break;
            }

        }
    };

    registerReceiver(wifiStateChangedReceiver, new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION));

}

From source file:com.android.launcher3.widget.DigitalAppWidgetProvider.java

@Override
public void onReceive(Context context, Intent intent) {
    mComtext = context;/*from ww w. j a va  2  s .  c om*/
    String action = intent.getAction();
    Log.i("sai", "onReceive: " + action);

    super.onReceive(context, intent);

    if (ACTION_ON_QUARTER_HOUR.equals(action) || Intent.ACTION_DATE_CHANGED.equals(action)
            || Intent.ACTION_TIMEZONE_CHANGED.equals(action) || Intent.ACTION_TIME_CHANGED.equals(action)
            || Intent.ACTION_LOCALE_CHANGED.equals(action)) {
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
        if (appWidgetManager != null) {
            int[] appWidgetIds = appWidgetManager.getAppWidgetIds(getComponentName(context));
            for (int appWidgetId : appWidgetIds) {
                RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.digital_appwidget);
                float ratio = WidgetUtils.getScaleRatio(context, null, appWidgetId);
                // SPRD for bug421127 add am/pm for widget
                WidgetUtils.setTimeFormat(widget,
                        (int) context.getResources().getDimension(R.dimen.widget_label_font_size),
                        R.id.the_clock);
                WidgetUtils.setClockSize(context, widget, ratio);
                //refreshAlarm(context, widget);
                appWidgetManager.partiallyUpdateAppWidget(appWidgetId, widget);
            }
        }
        if (!ACTION_ON_QUARTER_HOUR.equals(action)) {
            cancelAlarmOnQuarterHour(context);
        }
        startAlarmOnQuarterHour(context);
    }
    // cg sai.pan begin
    else if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
        if (appWidgetManager != null) {
            int[] appWidgetIds = appWidgetManager.getAppWidgetIds(getComponentName(context));
            for (int appWidgetId : appWidgetIds) {
                RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.digital_appwidget);
                refreshBtStatus(context, widget);
                appWidgetManager.partiallyUpdateAppWidget(appWidgetId, widget);
            }
        }
    } else if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)) {
        int wifiStatus = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, 0);
        Log.e("sai", "wifiStatus" + wifiStatus);
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
        if (appWidgetManager != null) {
            int[] appWidgetIds = appWidgetManager.getAppWidgetIds(getComponentName(context));
            for (int appWidgetId : appWidgetIds) {
                RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.digital_appwidget);
                if (WifiManager.WIFI_STATE_ENABLED == wifiStatus
                        || WifiManager.WIFI_STATE_ENABLING == wifiStatus) {
                    widget.setImageViewResource(R.id.wifi, R.drawable.status_wifi_on);
                } else {
                    widget.setImageViewResource(R.id.wifi, R.drawable.status_wifi_off);
                }
                appWidgetManager.partiallyUpdateAppWidget(appWidgetId, widget);
            }
        }
    } else if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) {
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
        if (appWidgetManager != null) {
            int[] appWidgetIds = appWidgetManager.getAppWidgetIds(getComponentName(context));
            for (int appWidgetId : appWidgetIds) {
                RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.digital_appwidget);
                refreshWifiStatus(context, widget);
            }
        }
    } else if ("android.net.conn.CONNECTIVITY_CHANGE".equals(action)) {
        if (isNetworkConnected(context)) {
            Log.e("sai", "isNetworkConnected true");
            requestLocation(context);
        } else {
            Log.e("sai", "isNetworkConnected false");
        }
    }
}