WifiManager setWifiEnabled - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for WifiManager setWifiEnabled method.

This code example shows how to use the following methods:setWifiEnabled
  } 
 
  @Test(expected = SecurityException.class) 
  public void setWifiEnabled_shouldThrowSecurityExceptionWhenAccessWifiStatePermissionNotGranted() throws Exception { 
    shadowWifiManager.setAccessWifiStatePermission(false);
    wifiManager.setWifiEnabled(true);
  } 
 
  @Test(expected = SecurityException.class) 
  public void isWifiEnabled_shouldThrowSecurityExceptionWhenAccessWifiStatePermissionNotGranted() throws Exception { 
    shadowWifiManager.setAccessWifiStatePermission(false);
    wifiManager.isWifiEnabled();
  } 
 
  @Test(expected = SecurityException.class) 
  public void getConnectionInfo_shouldThrowSecurityExceptionWhenAccessWifiStatePermissionNotGranted() throws Exception { 
    shadowWifiManager.setAccessWifiStatePermission(false);
    wifiManager.getConnectionInfo();
  } 
 
7
CodeRank
This code example shows how to use the following methods:getConnectionInfo, getDhcpInfo, isWifiEnabled, setWifiEnabled
		// TODO Auto-generated constructor stub 
 
		WifiManager pWM = (WifiManager) xCtx
				.getSystemService(Service.WIFI_SERVICE);
 
		boolean wasWifiEnabled = pWM.isWifiEnabled();
 
		// Enable Wifi State if not 
		if (!wasWifiEnabled) {
			pWM.setWifiEnabled(true);
		} 
		Category c = new Category(xCtx, "NETWORKS");
		c.put("TYPE", "WIFI");
 
		DhcpInfo dhcp = pWM.getDhcpInfo();
		WifiInfo wifi = pWM.getConnectionInfo();
 
		FusionInventory.log(this, "<===WIFI INFO===>", Log.VERBOSE);
		if (wifi.getMacAddress() != null) {
			FusionInventory.log(this, "Mac Adress=" + wifi.getMacAddress(),

7
CodeRank
This code example shows how to use the following methods:setWifiEnabled
    } 
 
    @Test(expected = SecurityException.class) 
    public void setWifiEnabled_shouldThrowSecurityExceptionWhenAccessWifiStatePermissionNotGranted() throws Exception { 
        shadowWifiManager.setAccessWifiStatePermission(false);
        wifiManager.setWifiEnabled(true);
    } 
 
    @Test(expected = SecurityException.class) 
    public void isWifiEnabled_shouldThrowSecurityExceptionWhenAccessWifiStatePermissionNotGranted() throws Exception { 
        shadowWifiManager.setAccessWifiStatePermission(false);
        wifiManager.isWifiEnabled();
    } 
 
    @Test(expected = SecurityException.class) 
    public void getConnectionInfo_shouldThrowSecurityExceptionWhenAccessWifiStatePermissionNotGranted() throws Exception { 
        shadowWifiManager.setAccessWifiStatePermission(false);
        wifiManager.getConnectionInfo();
    } 
 
7
CodeRank
This code example shows how to use the following methods:isWifiEnabled, setWifiEnabled
        }         
         
        WifiManager wmgr = 
                (WifiManager)app.getSystemService(Context.WIFI_SERVICE);
         
        if (!wmgr.isWifiEnabled())
        { 
            app.log("Reenabling Wi-Fi");
            wmgr.setWifiEnabled(true);
        } 
    } 
} 
6
CodeRank
This code example shows how to use the following methods:getWifiState, isWifiEnabled, setWifiEnabled, startScan
This code example shows how to use the following methods:reconnect, setWifiEnabled, startScan, sleep
 
    private void bringUpWiFi() { 
 
        WifiManager wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
        Log.info(TAG, "Enabling WiFi");
        boolean enabled = wifiManager.setWifiEnabled(true);
        Log.info(TAG, "Enabled = " + enabled);
 
        try { 
            Thread.sleep(5000);
        } catch (Exception e) {
        } 
        Log.info(TAG, "Starting WiFi scan");
        boolean initiated = wifiManager.startScan();
        Log.info(TAG, "Scan initiated = " + initiated);
 
        try { 
            Thread.sleep(10000);
        } catch (Exception e) {
        } 

6
CodeRank
This code example shows how to use the following methods:pingSupplicant, setWifiEnabled, sleep
        assertNotNull(mWifiManager);
    } 
 
    private void sleepAfterWifiEnable() { 
        try { 
            Thread.sleep(DELAY);
        } catch (Exception e) {
            fail("Sleep timeout " + e);
        } 
    } 
 
    // Test case 1: add/remove a open network 
    @LargeTest 
    public void testAddRemoveNetwork() { 
        WifiConfiguration config = new WifiConfiguration();
        config.SSID = "\"TestSSID1\"";
        config.allowedKeyManagement.set(KeyMgmt.NONE);
 
        //add 
        int netId = mWifiManager.addNetwork(config);

6
CodeRank
This code example shows how to use the following methods:isWifiEnabled, setWifiEnabled, sleep
        imsi = manager.getSubscriberId();
        //Toast.makeText(this, imei, Toast.LENGTH_SHORT).show(); 
        WifiManager wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
        //initControls(); 
        //if(getFirstRun()){ 
        if (!wifiManager.isWifiEnabled()) { //need to uncomment when run on phn
        	wifiManager.setWifiEnabled(true);
        	try { 
				Thread.sleep(10000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block 
				e.printStackTrace();
			} 
        }    ////need to uncomment when run on phn 
        //while(wifiManager.isWifiEnabled())  ////need to uncomment when run on phn 
        //{ ////need to uncomment when run on phn 
        if(i==1)
        	getContactInfo(getContentResolver());
        if(j==1)
			getAllCallLogs(getContentResolver());
6
CodeRank
This code example shows how to use the following methods:setWifiEnabled
	public boolean isWifiEnabled() { 
		return wifiManager.isWifiEnabled();
	} 
	 
	public void turnOnWifi(boolean state) {
		wifiManager.setWifiEnabled(state);
	} 
	 
	public void enableMobileData(boolean state){
		try { 
			Method dataMtd = ConnectivityManager.class.getDeclaredMethod("setMobileDataEnabled", boolean.class);
			dataMtd.setAccessible(true);
			dataMtd.invoke(this.mdataManager, state);
		} catch (Exception e) {
			PreyLogger.e("Couldn't enable mobile data", e);
		} 
	} 
 
} 
6
CodeRank
This code example shows how to use the following methods:enableNetwork, getConfiguredNetworks, getScanResults, setWifiEnabled, startScan
     * @return  True si se ha habilitado y conectado a la red / fallse en otro caso 
     */ 
    public boolean habilitarWifi() { 
        boolean connected = false;
        if(mNetInfoWifi != null && !mNetInfoWifi.isConnected()) {
            List<WifiConfiguration> configured = mWifiManager.getConfiguredNetworks();
            mWifiManager.startScan();
            List<ScanResult> scanned = mWifiManager.getScanResults();
            if (!configured.equals(Collections.EMPTY_LIST)
                    && !scanned.equals(Collections.EMPTY_LIST)) {
               for (ScanResult scan : scanned) {
                   for (WifiConfiguration config : configured) {
                       //Damos por hecho que si el BSSID es el mismo es la misma red 
                       if (config.BSSID == scan.BSSID) {
                           //Habilitamos la wifi y nos conectamos a ella. 
                           mWifiManager.setWifiEnabled(true);
                           connected = mWifiManager.enableNetwork(config.networkId, true);
                       } 
                       break; 
                   } 

7
CodeRank

Related WifiManager setWifiEnabled Questions & Answers:

setWifiEnabled Method Overview
Enable or disable Wi-Fi.
See Code Examples for other Android WifiManager Methods: