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.example.sensingapp.SensingApp.java

public void show_screen2() {
    int i;//w w w.j  a v  a 2 s.  c  o  m
    Location location = null;

    setContentView(R.layout.screen_2_sensors);

    m_chkAccl = (CheckBox) findViewById(R.id.chkAccl);
    m_chkLinearAccl = (CheckBox) findViewById(R.id.chkLinearAccl);
    m_chkGravity = (CheckBox) findViewById(R.id.chkGravity);
    m_chkGyro = (CheckBox) findViewById(R.id.chkGyro);
    m_chkOrient = (CheckBox) findViewById(R.id.chkOrient);
    m_chkMagnet = (CheckBox) findViewById(R.id.chkMagnetic);
    m_chkLight = (CheckBox) findViewById(R.id.chkLight);
    m_chkBarometer = (CheckBox) findViewById(R.id.chkBarometer);

    m_chkMic = (CheckBox) findViewById(R.id.chkMic);
    m_chkCellular = (CheckBox) findViewById(R.id.chkCellular);

    m_chkGPS = (CheckBox) findViewById(R.id.chkGPS);
    m_chkWifi = (CheckBox) findViewById(R.id.chkWifi);

    m_chkAccl.setOnCheckedChangeListener(m_chkSensorEnableListener);
    m_chkLinearAccl.setOnCheckedChangeListener(m_chkSensorEnableListener);
    m_chkGravity.setOnCheckedChangeListener(m_chkSensorEnableListener);
    m_chkGyro.setOnCheckedChangeListener(m_chkSensorEnableListener);
    m_chkOrient.setOnCheckedChangeListener(m_chkSensorEnableListener);
    m_chkMagnet.setOnCheckedChangeListener(m_chkSensorEnableListener);
    m_chkLight.setOnCheckedChangeListener(m_chkSensorEnableListener);
    m_chkBarometer.setOnCheckedChangeListener(m_chkSensorEnableListener);
    m_chkMic.setOnCheckedChangeListener(m_chkSensorEnableListener);
    m_chkCellular.setOnCheckedChangeListener(m_chkSensorEnableListener);

    m_chkGPS.setOnCheckedChangeListener(m_chkSensorEnableListener);
    m_chkWifi.setOnCheckedChangeListener(m_chkSensorEnableListener);

    m_spnScreen2_WiFiScanSpeed = (Spinner) findViewById(R.id.Screen2_spnWiFiScanSpeed);

    m_adpWiFiScanSpeed = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,
            m_arrsWiFiScanSpeed);
    m_adpWiFiScanSpeed.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    m_spnScreen2_WiFiScanSpeed.setAdapter(m_adpWiFiScanSpeed);
    m_spnScreen2_WiFiScanSpeed.setSelection(m_nWifiScanSpeedIndex);

    m_rdgpSensor = (RadioGroup) findViewById(R.id.RdGpSensor);
    m_rdSensorAccl = (RadioButton) findViewById(R.id.RdSensor_Accl);
    m_rdSensorLinearAccl = (RadioButton) findViewById(R.id.RdSensor_LinearAccl);
    m_rdSensorGravity = (RadioButton) findViewById(R.id.RdSensor_Gravity);
    m_rdSensorGyro = (RadioButton) findViewById(R.id.RdSensor_Gyro);
    m_rdSensorOrient = (RadioButton) findViewById(R.id.RdSensor_Orient);
    m_rdSensorMagnet = (RadioButton) findViewById(R.id.RdSensor_Magnetic);
    m_rdSensorLight = (RadioButton) findViewById(R.id.RdSensor_Light);
    m_rdSensorBarometer = (RadioButton) findViewById(R.id.RdSensor_Barometer);

    m_rdgpSensorMode = (RadioGroup) findViewById(R.id.RdGpSensorMode);
    m_rdSensorModeFastest = (RadioButton) findViewById(R.id.RdSensorMode_Fastest);
    m_rdSensorModeGame = (RadioButton) findViewById(R.id.RdSensorMode_Game);
    m_rdSensorModeNormal = (RadioButton) findViewById(R.id.RdSensorMode_Normal);
    m_rdSensorModeUI = (RadioButton) findViewById(R.id.RdSensorMode_UI);

    m_rdgpSensor.setOnCheckedChangeListener(m_rdgpSensorListener);
    m_rdgpSensorMode.setOnCheckedChangeListener(m_rdgpSensorModeListener);

    configSensorOptionStatus();

    m_mainWifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    if (m_mainWifi.getWifiState() == WifiManager.WIFI_STATE_ENABLED) {
        m_blnWifiSignalEnabled = true;
    } else {
        m_blnWifiSignalEnabled = false;
        m_chkWifi.setEnabled(false);
    }

    this.registerReceiver(m_brcvWifiStateChangedReceiver,
            new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION));

    m_locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    m_blnGPSSignalEnabled = m_locManager.isProviderEnabled(m_sGPSProvider);

    if ((m_locManager != null) && (m_blnGPSSignalEnabled == true)) {
        location = m_locManager.getLastKnownLocation(m_sGPSProvider);
        if (location != null) {
            float fLat = (float) (location.getLatitude());
            float fLng = (float) (location.getLongitude());
            if (location.hasAltitude()) {
                float fAlt = (float) (location.getAltitude());
            }
        }
    }

    m_btnScreen2_Back = (Button) findViewById(R.id.btScreen2_Back);
    m_btnScreen2_Back.setOnClickListener(m_btnScreen2_Back_Listener);
    m_btnScreen2_Next = (Button) findViewById(R.id.btScreen2_Next);
    m_btnScreen2_Next.setOnClickListener(m_btnScreen2_Next_Listener);

    /* No sensor is installed, disable other widgets and show information to user */
    if ((m_blnOrientPresent == false) && (m_blnGyroPresent == false) && (m_blnAcclPresent == false)
            && (m_blnLinearAcclPresent == false) && (m_blnGravityPresent == false)
            && (m_blnMagnetPresent == false) && (m_blnLightPresent == false)
            && (m_blnBarometerPresent == false)) {

        m_rdSensorModeFastest.setEnabled(false);
        m_rdSensorModeGame.setEnabled(false);
        m_rdSensorModeNormal.setEnabled(false);
        m_rdSensorModeUI.setEnabled(false);

    }

    if (m_blnAcclEnabled == true) {
        m_chkAccl.setChecked(true);
    }

    if (m_blnLinearAcclEnabled == true) {
        m_chkLinearAccl.setChecked(true);
    }

    if (m_blnGravityEnabled == true) {
        m_chkGravity.setChecked(true);
    }

    if (m_blnGyroEnabled == true) {
        m_chkGyro.setChecked(true);
    }

    if (m_blnOrientEnabled == true) {
        m_chkOrient.setChecked(true);
    }

    if (m_blnMagnetEnabled == true) {
        m_chkMagnet.setChecked(true);
    }

    if (m_blnLightEnabled == true) {
        m_chkLight.setChecked(true);
    }

    if (m_blnBarometerEnabled == true) {
        m_chkBarometer.setChecked(true);
    }

    if (m_blnMicEnabled == true) {
        m_chkMic.setChecked(true);
    }

    if (m_blnCellularEnabled == true) {
        m_chkCellular.setChecked(true);
    }

    if (m_blnGPSEnabled == true) {
        m_chkGPS.setChecked(true);
    }

    if (m_blnWifiEnabled == true) {
        m_chkWifi.setChecked(true);
    }

    Settings.System.putInt(getContentResolver(), Settings.System.WIFI_SLEEP_POLICY,
            Settings.System.WIFI_SLEEP_POLICY_NEVER);

}