Example usage for android.net.wifi WifiManager WIFI_STATE_CHANGED_ACTION

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

Introduction

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

Prototype

String WIFI_STATE_CHANGED_ACTION

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

Click Source Link

Document

Broadcast intent action indicating that Wi-Fi has been enabled, disabled, enabling, disabling, or unknown.

Usage

From source file:com.hzl.administrator.wifi.WifiStatusTest.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mWifiManager = (WifiManager) getSystemService(WIFI_SERVICE);

    mWifiStateFilter = new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION);
    mWifiStateFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
    mWifiStateFilter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
    mWifiStateFilter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION);
    mWifiStateFilter.addAction(WifiManager.RSSI_CHANGED_ACTION);
    mWifiStateFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);

    registerReceiver(mWifiStateReceiver, mWifiStateFilter);

    setContentView(R.layout.wifi_status_test);

    updateButton = (Button) findViewById(R.id.update);
    updateButton.setOnClickListener(updateButtonHandler);

    mWifiState = (TextView) findViewById(R.id.wifi_state);
    mNetworkState = (TextView) findViewById(R.id.network_state);
    mSupplicantState = (TextView) findViewById(R.id.supplicant_state);
    mRSSI = (TextView) findViewById(R.id.rssi);
    mBSSID = (TextView) findViewById(R.id.bssid);
    mSSID = (TextView) findViewById(R.id.ssid);
    mHiddenSSID = (TextView) findViewById(R.id.hidden_ssid);
    mIPAddr = (TextView) findViewById(R.id.ipaddr);
    mMACAddr = (TextView) findViewById(R.id.macaddr);
    mNetworkId = (TextView) findViewById(R.id.networkid);
    mLinkSpeed = (TextView) findViewById(R.id.link_speed);
    mScanList = (TextView) findViewById(R.id.scan_list);

    mPingIpAddr = (TextView) findViewById(R.id.pingIpAddr);
    mPingHostname = (TextView) findViewById(R.id.pingHostname);
    mHttpClientTest = (TextView) findViewById(R.id.httpClientTest);

    pingTestButton = (Button) findViewById(R.id.ping_test);
    pingTestButton.setOnClickListener(mPingButtonHandler);
}

From source file:ch.bfh.instacircle.NetworkActiveActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_network_active);

    // Create the adapter that will return a fragment for each of the three
    // primary sections of the app.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override/*  w w  w. j  ava2 s. co  m*/
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
        actionBar
                .addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }

    // Handle the change of the Wifi configuration
    wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    adhoc = new AdhocWifiManager(wifi);
    wifiapmanager = new WifiAPManager();
    registerReceiver(wifiReceiver, new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION));

    // Is NFC available on this device?
    nfcAvailable = this.getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC);

    // only set up the NFC stuff if NFC is also available
    if (nfcAvailable) {
        nfcAdapter = NfcAdapter.getDefaultAdapter(this);
        if (nfcAdapter.isEnabled()) {

            // Setting up a pending intent that is invoked when an NFC tag
            // is tapped on the back
            pendingIntent = PendingIntent.getActivity(this, 0,
                    new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);

            nfcIntentFilter = new IntentFilter();
            nfcIntentFilter.addAction(NfcAdapter.ACTION_NDEF_DISCOVERED);
            nfcIntentFilter.addAction(NfcAdapter.ACTION_TAG_DISCOVERED);
            intentFiltersArray = new IntentFilter[] { nfcIntentFilter };
        } else {
            nfcAvailable = false;
        }
    }
}

From source file:net.micode.fileexplorer.ServerControlActivity.java

public void onResume() {
    super.onResume();

    UiUpdater.registerClient(handler);/*from w  w w. j a v  a  2 s. c o  m*/
    updateUi();
    // Register to receive wifi status broadcasts
    myLog.l(Log.DEBUG, "Registered for wifi updates");
    IntentFilter filter = new IntentFilter();
    filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
    filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    mActivity.registerReceiver(wifiReceiver, filter);
}

From source file:org.mozilla.mozstumbler.service.stumblerthread.scanners.WifiScanner.java

public void onProxyReceive(Context c, Intent intent) {
    String action = intent.getAction();

    if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)) {
        if (isScanEnabled()) {
            activatePeriodicScan(ActiveOrPassiveStumbling.ACTIVE_STUMBLING);
        } else {//from w  w  w .  j a v a 2s .c  om
            deactivatePeriodicScan();
        }
    } else if (WifiManager.SCAN_RESULTS_AVAILABLE_ACTION.equals(action)) {
        final List<ScanResult> scanResultList = wifiManagerProxy.getScanResults();
        if (scanResultList == null) {
            return;
        }

        final ArrayList<ScanResult> scanResults = new ArrayList<ScanResult>();
        for (ScanResult scanResult : scanResultList) {
            scanResult.BSSID = BSSIDBlockList.canonicalizeBSSID(scanResult.BSSID);
            if (shouldLog(scanResult)) {
                scanResults.add(scanResult);
            }
        }
        mVisibleAPs.set(scanResults.size());
        reportScanResults(scanResults);
    }
}

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

@Override
public void onResume() {
    serviceCheckBox.setChecked(!PrefUtil.readBoolean(getActivity(), Pref.DISABLESERVICE.key()));
    wifiCheckBox.setChecked(AsyncWifiManager.getWifiManager(getActivity()).isWifiEnabled());
    logCheckBox.setChecked(PrefUtil.readBoolean(getActivity(), Pref.DEBUG.key()));
    getActivity().registerReceiver(wifiReceiver, new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION));
    super.onResume();
}

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

private void scan() {
    if (!wifiState && !wifiOn) {
        networkListFragment.setMessage(R.string.msg_nowifi);
        return;//from  w w  w.j  a va  2s  . com
    }
    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:com.android.launcher3.widget.DigitalAppWidgetProvider.java

@Override
public void onReceive(Context context, Intent intent) {
    mComtext = context;/*from   w  ww  . j  ava2s  .  c  o  m*/
    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");
        }
    }
}

From source file:de.j4velin.wifiAutoOff.Preferences.java

@Override
public void onResume() {
    super.onResume();
    final CheckBoxPreference no_network_off = (CheckBoxPreference) findPreference("off_no_network");
    no_network_off.setSummary(getString(R.string.for_at_least, PreferenceManager
            .getDefaultSharedPreferences(this).getInt("no_network_timeout", Receiver.TIMEOUT_NO_NETWORK)));
    handler.postDelayed(signalUpdater, 1000);
    IntentFilter ifilter = new IntentFilter(WifiManager.NETWORK_STATE_CHANGED_ACTION);
    ifilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
    registerReceiver(stateChangedReceiver, ifilter);
}

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

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

    wifiStateChangedReceiver = new BroadcastReceiver() {

        @Override//from  w  w  w  .  jav a 2  s. com
        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));

}