Example usage for android.content Context WIFI_SERVICE

List of usage examples for android.content Context WIFI_SERVICE

Introduction

In this page you can find the example usage for android.content Context WIFI_SERVICE.

Prototype

String WIFI_SERVICE

To view the source code for android.content Context WIFI_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.net.wifi.WifiManager for handling management of Wi-Fi access.

Usage

From source file:com.android.launcher3.Utilities.java

public static void turnOffWifi(Activity activity) {
    WifiManager wifimanager = (WifiManager) activity.getApplicationContext()
            .getSystemService(Context.WIFI_SERVICE);
    wifimanager.setWifiEnabled(false);/*  w  w  w .  j  av  a  2 s  .co m*/
    isWifiOn = false;
}

From source file:com.sentaroh.android.TaskAutomation.TaskExecutor.java

final static public boolean setWifiDisableSsid(TaskManagerParms taskMgrParms, EnvironmentParms envParms,
        CommonUtilities util, TaskResponse taskResponse, ActionResponse ar) {
    WifiManager wm = (WifiManager) taskMgrParms.context.getSystemService(Context.WIFI_SERVICE);
    int nwid = wm.getConnectionInfo().getNetworkId();
    if (envParms.isWifiConnected()) {
        if (!envParms.wifiSsid.equals(EnvironmentParms.WIFI_DIRECT_SSID)) {
            wm.disableNetwork(nwid);//from  w  ww .  java 2s  . co m
            ar.action_resp = ActionResponse.ACTION_SUCCESS;
            ar.resp_msg_text = "";
            return true;
        } else {
            ar.action_resp = ActionResponse.ACTION_WARNING;
            ar.resp_msg_text = "Can not disabled, WiFi is connected to WiFi-Direct";
            return false;
        }
    }
    ar.action_resp = ActionResponse.ACTION_WARNING;
    ar.resp_msg_text = "Wifi not connected";
    return false;
}

From source file:com.sentaroh.android.TaskAutomation.TaskExecutor.java

final static public boolean setWifiRemoveSsid(TaskManagerParms taskMgrParms, EnvironmentParms envParms,
        CommonUtilities util, TaskResponse taskResponse, ActionResponse ar) {
    WifiManager wm = (WifiManager) taskMgrParms.context.getSystemService(Context.WIFI_SERVICE);
    int nwid = wm.getConnectionInfo().getNetworkId();
    if (envParms.isWifiConnected()) {
        if (!envParms.wifiSsid.equals(EnvironmentParms.WIFI_DIRECT_SSID)) {
            wm.removeNetwork(nwid);//  w w  w.j a va 2s.co  m
            ar.action_resp = ActionResponse.ACTION_SUCCESS;
            ar.resp_msg_text = "";
            return true;
        } else {
            ar.action_resp = ActionResponse.ACTION_WARNING;
            ar.resp_msg_text = "Can not removed, WiFi is connected to WiFi-Direct";
            return false;
        }
    }
    ar.action_resp = ActionResponse.ACTION_WARNING;
    ar.resp_msg_text = "Wifi not connected";
    return false;
}

From source file:com.example.sensingapp.SensingApp.java

public void show_screen2() {
    int i;//  ww w.j a v a  2  s.  c  om
    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);

}

From source file:com.sentaroh.android.TaskAutomation.TaskExecutor.java

final static public void setWifiOn(TaskManagerParms taskMgrParms, EnvironmentParms envParms,
        CommonUtilities util, TaskResponse task_response, ActionResponse ar) {
    WifiManager wm = (WifiManager) taskMgrParms.context.getSystemService(Context.WIFI_SERVICE);
    int ws = -1;/*ww  w  .j  a va  2 s .  c o  m*/
    if (wm != null)
        ws = wm.getWifiState();
    if (envParms.settingDebugLevel >= 1)
        util.addDebugMsg(1, "I",
                "setWifiOn WIFI On entered, wifiIsActive=" + envParms.wifiIsActive + ", wifiMgrStatus=" + ws);
    if (!envParms.wifiIsActive) {
        if (wm != null) {
            if (wm.setWifiEnabled(true)) {
                ar.action_resp = ActionResponse.ACTION_SUCCESS;
                ar.resp_msg_text = "setWifiOn WIFI On Success";
            } else {
                if (envParms.settingDebugLevel >= 1)
                    util.addDebugMsg(1, "I", "setWifiOn WifiManager error, WIFI On ignored");
                ar.action_resp = ActionResponse.ACTION_WARNING;
                ar.resp_msg_text = "setWifiOn WifiManager error";
            }
        } else {
            if (envParms.settingDebugLevel >= 1)
                util.addDebugMsg(1, "I", "setWifiOn WifiManager not available, WIFI On ignored");
            ar.action_resp = ActionResponse.ACTION_WARNING;
            ar.resp_msg_text = "setWifiOn WIFI not available";
        }
    } else {
        ar.action_resp = ActionResponse.ACTION_WARNING;
        ar.resp_msg_text = "setWifiOn WIFI already on";
    }
}

From source file:com.sentaroh.android.TaskAutomation.TaskExecutor.java

final static public void setWifiOff(TaskManagerParms taskMgrParms, EnvironmentParms envParms,
        CommonUtilities util, TaskResponse task_response, ActionResponse ar) {
    WifiManager wm = (WifiManager) taskMgrParms.context.getSystemService(Context.WIFI_SERVICE);
    int ws = -1;//from   w w w .  j a va 2 s  .  c o m
    if (wm != null)
        ws = wm.getWifiState();
    if (envParms.settingDebugLevel >= 1)
        util.addDebugMsg(1, "I",
                "setWifiOff WIFI Off entered, wifiIsActive=" + envParms.wifiIsActive + ", wifiMgrStatus=" + ws);
    if (envParms.wifiIsActive) {
        if (wm != null) {
            wm.setWifiEnabled(false);
            ar.action_resp = ActionResponse.ACTION_SUCCESS;
            ar.resp_msg_text = "setWifiOff WIFI Off Success";
        } else {
            if (envParms.settingDebugLevel >= 1)
                util.addDebugMsg(1, "I", "setWifiOff WifiManager not available, WIFI Off ignored");
            ar.action_resp = ActionResponse.ACTION_WARNING;
            ar.resp_msg_text = "setWifiOff WIFI not available";
        }
    } else {
        ar.action_resp = ActionResponse.ACTION_WARNING;
        ar.resp_msg_text = "setWifiOff WIFI already off";
    }
}

From source file:com.lgallardo.qbittorrentclient.RefreshListener.java

protected void getSettings() {
    // Preferences stuff
    sharedPrefs = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);

    builderPrefs = new StringBuilder();

    builderPrefs.append("\n" + sharedPrefs.getString("language", "NULL"));

    // Get values from preferences
    currentServer = sharedPrefs.getString("currentServer", "1");
    hostname = sharedPrefs.getString("hostname", "");
    subfolder = sharedPrefs.getString("subfolder", "");

    protocol = sharedPrefs.getString("protocol", "NULL");

    // If user leave the field empty, set 8080 port
    try {/*from  www.  j  a  v  a2 s  .com*/
        port = Integer.parseInt(sharedPrefs.getString("port", "8080"));
    } catch (NumberFormatException e) {
        port = 8080;

    }
    username = sharedPrefs.getString("username", "NULL");
    password = sharedPrefs.getString("password", "NULL");
    https = sharedPrefs.getBoolean("https", false);

    // Check https
    if (https) {
        protocol = "https";
    } else {
        protocol = "http";
    }

    // Get refresh info
    auto_refresh = sharedPrefs.getBoolean("auto_refresh", true);

    try {
        refresh_period = Integer.parseInt(sharedPrefs.getString("refresh_period", "120000"));
    } catch (NumberFormatException e) {
        refresh_period = 120000;
    }

    // Get connection and data timeouts
    try {
        connection_timeout = Integer.parseInt(sharedPrefs.getString("connection_timeout", "10"));

        // New default value to make it work with qBittorrent 3.2.x
        if (connection_timeout < 10) {
            connection_timeout = 10;
        }
    } catch (NumberFormatException e) {
        connection_timeout = 10;
    }

    try {
        data_timeout = Integer.parseInt(sharedPrefs.getString("data_timeout", "20"));

        // New default value to make it work with qBittorrent 3.2.x
        if (data_timeout < 20) {
            data_timeout = 20;
        }

    } catch (NumberFormatException e) {
        data_timeout = 20;
    }

    sortby_value = sharedPrefs.getInt("sortby_value", 1);
    reverse_order = sharedPrefs.getBoolean("reverse_order", false);

    dark_ui = sharedPrefs.getBoolean("dark_ui", false);

    qb_version = sharedPrefs.getString("qb_version", "3.2.x");

    MainActivity.cookie = sharedPrefs.getString("qbCookie", null);

    // Get last state
    lastState = sharedPrefs.getString("lastState", "all");

    // Get last label
    //        lastLabel = sharedPrefs.getString("lastLabel", "all");
    lastLabel = sharedPrefs.getString("lastLabel", "all");
    currentLabel = lastLabel;

    // Notification check
    enable_notifications = sharedPrefs.getBoolean("enable_notifications", false);

    try {
        notification_period = Long.parseLong(sharedPrefs.getString("notification_period", "120000L"));
    } catch (NumberFormatException e) {
        notification_period = 120000L;
    }

    header = sharedPrefs.getBoolean("header", true);

    // Get package info
    PackageInfo pInfo = null;
    try {
        pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }

    // Get package name
    packageName = pInfo.packageName;
    packageVersion = pInfo.versionName;

    // Get AlternativeSpeedLimitsEnabled value
    alternative_speeds = sharedPrefs.getBoolean("alternativeSpeedLimitsEnabled", false);

    // Get local SSID properties
    ssid = sharedPrefs.getString("ssid", "");
    local_hostname = sharedPrefs.getString("local_hostname", null);

    // If user leave the field empty, set 8080 port
    try {
        local_port = Integer.parseInt(sharedPrefs.getString("local_port", "-1"));
    } catch (NumberFormatException e) {
        local_port = -1;

    }

    // Set SSI and local hostname and port
    if (ssid != null && !ssid.equals("")) {

        // Get SSID if WiFi
        WifiManager wifiMgr = (WifiManager) getSystemService(Context.WIFI_SERVICE);
        WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
        String wifiSSID = wifiInfo.getSSID();

        //            Log.d("Debug", "WiFi SSID: " + wifiSSID);
        //            Log.d("Debug", "SSID: " + ssid);

        if (wifiSSID.toUpperCase().equals("\"" + ssid.toUpperCase() + "\"")
                && wifiMgr.getWifiState() == WifiManager.WIFI_STATE_ENABLED) {

            if (local_hostname != null && !local_hostname.equals("")) {
                hostname = local_hostname;
            }

            if (local_port != -1) {
                port = local_port;
            }

            //                Log.d("Debug", "hostname: " + hostname);
            //                Log.d("Debug", "port: " + port);
            //                Log.d("Debug", "local_hostname: " + local_hostname);
            //                Log.d("Debug", "local_port: " + local_port);

        }
    }

    // Get keystore for self-signed certificate
    keystore_path = sharedPrefs.getString("keystore_path" + currentServer, "");
    keystore_password = sharedPrefs.getString("keystore_password" + currentServer, "");

}

From source file:com.android.mms.ui.MessageUtils.java

public static boolean isWifiConnected(Context context) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo wifi = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    MmsLog.d(TAG, "wifi state:" + wifiManager.getWifiState() + "wifi connected:" + wifi.isConnected());
    if (wifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLED && wifi.isConnected()) {
        MmsLog.d(TAG, "Wifi connected");
        return true;
    }/*from w  ww  . ja v a2s .  c o m*/
    MmsLog.d(TAG, "Wifi off or not connected");
    return false;
}

From source file:com.guardtrax.ui.screens.HomeScreen.java

private void loadPreferenceDataBase() {
    //get the default values
    //List<String> defaults = OptionsScreen.loadDefaults();

    String uniqueID = "";

    //get the IMEI number
    try {/*  w w  w . j a v a2s .  c o m*/
        TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
        if (tm != null)
            uniqueID = tm.getDeviceId();
        if (uniqueID == null || uniqueID.length() == 0) {
            WifiManager wifimanager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
            if (wifimanager != null)
                uniqueID = wifimanager.getConnectionInfo().getMacAddress();
        }
        if (uniqueID == null)
            uniqueID = BluetoothAdapter.getDefaultAdapter().getAddress();
        if (uniqueID == null)
            uniqueID = "123456789";
    } catch (Exception e) {
        uniqueID = "987654321";
    }

    String uniqueIdDB = Utility.getUniqueNumber(uniqueID);

    //get the type of phone  (GSM,CDMA) and put into constants
    GTConstants.PHONE_TYPE = getPhoneType();

    //Load into new database 
    preferenceDB.open();

    id = preferenceDB.insertRecord(GTConstants.LOCATIONUPDATESINTERVAL,
            GTConstants.LOCATIONUPDATEDISTANCEINTERVAL, GTConstants.SERVERIP,
            String.valueOf(GTConstants.SERVERPORT), GTConstants.PANIC_NUMBER, uniqueIdDB,
            String.valueOf(GTConstants.ACCELEROMETER_SPEED), GTConstants.LICENSE_ID, GTConstants.PHONE_TYPE,
            GTConstants.REGISTRATION);

    preferenceDB.close();

    //load into constants
    preferenceDB.open();
    cursor = preferenceDB.getRecordByRowID("1");

    saveInConstants(cursor);

    cursor.close();
    preferenceDB.close();

}