Android WifiConfiguration - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android WifiConfiguration class.

This code example shows how to use the following methods:
    assertThat(wifiManager.getScanResults()).isSameAs(scanResults);
  } 
 
  @Test 
  public void shouldRecordTheLastAddedNetwork() throws Exception { 
    WifiConfiguration wifiConfiguration = new WifiConfiguration();
    wifiConfiguration.networkId = -1;
    int networkId = wifiManager.addNetwork(wifiConfiguration);
    assertThat(networkId).isEqualTo(0);
    assertThat(wifiManager.getConfiguredNetworks().get(0)).isNotSameAs(wifiConfiguration);
    assertThat(wifiConfiguration.networkId).isEqualTo(-1);
    assertThat(wifiManager.getConfiguredNetworks().get(0).networkId).isEqualTo(0);
 
    WifiConfiguration anotherConfig = new WifiConfiguration();
    assertThat(wifiManager.addNetwork(anotherConfig)).isEqualTo(1);
    assertThat(anotherConfig.networkId).isEqualTo(-1);
    assertThat(wifiManager.getConfiguredNetworks().get(1).networkId).isEqualTo(1);
  } 
 
  @Test 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
        assertThat(wifiManager.getScanResults()).isSameAs(scanResults);
    } 
 
    @Test 
    public void shouldRecordTheLastAddedNetwork() throws Exception { 
        WifiConfiguration wifiConfiguration = new WifiConfiguration();
        wifiConfiguration.networkId = -1;
        int networkId = wifiManager.addNetwork(wifiConfiguration);
        assertThat(networkId).isEqualTo(0);
        assertThat(wifiManager.getConfiguredNetworks().get(0)).isNotSameAs(wifiConfiguration);
        assertThat(wifiConfiguration.networkId).isEqualTo(-1);
        assertThat(wifiManager.getConfiguredNetworks().get(0).networkId).isEqualTo(0);
 
        WifiConfiguration anotherConfig = new WifiConfiguration();
        assertThat(wifiManager.addNetwork(anotherConfig)).isEqualTo(1);
        assertThat(anotherConfig.networkId).isEqualTo(-1);
        assertThat(wifiManager.getConfiguredNetworks().get(1).networkId).isEqualTo(1);
    } 
 
    @Test 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:toString
        mWifiManager = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE);
        assertNotNull(mWifiManager);
        assertTrue(mWifiManager.setWifiApEnabled(null, true));
        mWifiConfig = mWifiManager.getWifiApConfiguration();
        if (mWifiConfig != null) {
            Log.v(TAG, "mWifiConfig is " + mWifiConfig.toString());
        } else { 
            Log.v(TAG, "mWifiConfig is null.");
        } 
    } 
 
    @Override 
    protected void tearDown() throws Exception { 
        Log.v(TAG, "turn off wifi tethering");
        mWifiManager.setWifiApEnabled(null, false);
        super.tearDown(); 
    } 
 
    // Test case 1: Test the soft AP SSID with letters 
    @LargeTest 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:toString
		} 
		return w;
	} 
 
	private WifiConfiguration getKeyAppropriateConfig(final String password) {
		WifiConfiguration wf = new WifiConfiguration();
		if (wf.toString().contains(BUGGED)) {
			/* 
			 * Add hidden fields on bugged Android 3.2+ configs 
			 */ 
			wf = addHiddenFields(wf);
		} 
		wf.SSID = StringUtil.addQuotes(network.SSID);
		if (network.capabilities.length() == 0) {
			wf.BSSID = network.BSSID;
			wf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
			wf.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
			return wf;
		} 
		wf.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:toString
        mWifiManager = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE);
        assertNotNull(mWifiManager);
        assertTrue(mWifiManager.setWifiApEnabled(null, true));
        mWifiConfig = mWifiManager.getWifiApConfiguration();
        if (mWifiConfig != null) {
            Log.v(TAG, "mWifiConfig is " + mWifiConfig.toString());
        } else { 
            Log.v(TAG, "mWifiConfig is null.");
        } 
    } 
 
    @Override 
    protected void tearDown() throws Exception { 
        Log.v(TAG, "turn off wifi tethering");
        mWifiManager.setWifiApEnabled(null, false);
        super.tearDown(); 
    } 
 
    // Test case 1: Test the soft AP SSID with letters 
    @LargeTest 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:toString
	} 
	 
	public void ReadWiFiCredentials() 
	{ 
		/** Related to the HTC vulnerability allowing to get wpa_supplicant.conf **/ 
		WifiConfiguration wc = new WifiConfiguration();
		String output = wc.toString();
		Log.v("ReadWiFiCredentials",output);
	} 
	 
	public void ReadContacts() 
	{ 
		ContentResolver cr = getContentResolver();
        Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,null, null, null, null);
         
        if (cur.getCount() > 0) {
        	while (cur.moveToNext()) {
        		String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
        		String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
        		 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
			wifiManager.setWifiEnabled(false);
			if (apName == null) {
				Log.e(TAG, "setWifiAPEnabled, Ap name is null");
				return false; 
			} 
			configuration = new WifiConfiguration();
			configuration.SSID = apName;
			configuration.allowedKeyManagement
					.set(WifiConfiguration.KeyMgmt.NONE);
		} else { 
			try { 
				Method method = wifiManager.getClass().getMethod(
						"getWifiApConfiguration"); 
				configuration = (WifiConfiguration) method.invoke(wifiManager);
			} catch (Exception e) {
				Log.e(TAG, "Can not get WiFi AP configuration, " + e);
			} 
		} 
 
		try { 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
    private void updateConfig(WifiConfiguration config){
        Xlog.v(TAG, "updateConfig()");
        if(config==null){
            return; 
        } 
        WifiConfiguration newConfig = new WifiConfiguration();
        newConfig.networkId = config.networkId;
        newConfig.priority = config.priority;
        mWifiManager.updateNetwork(newConfig);
    } 
} 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
      Log.w(TAG, "Unable to add network " + config.SSID);
    } 
  } 
 
  private static WifiConfiguration changeNetworkCommon(String ssid) {
    WifiConfiguration config = new WifiConfiguration();
    config.allowedAuthAlgorithms.clear();
    config.allowedGroupCiphers.clear();
    config.allowedKeyManagement.clear();
    config.allowedPairwiseCiphers.clear();
    config.allowedProtocols.clear();
    // Android API insists that an ascii SSID must be quoted to be correctly handled. 
    config.SSID = quoteNonHex(ssid);
    return config;
  } 
 
  // Adding a WEP network 
  private static void changeNetworkWEP(WifiManager wifiManager, String ssid, String password) {
    WifiConfiguration config = changeNetworkCommon(ssid);
    config.wepKeys[0] = quoteNonHex(password, 10, 26, 58);
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
	/** 
	 * create a hotSpot with out password 
	 *  
	 * */ 
	public void createHostGroup(String ssid) {
		WifiConfiguration config = new WifiConfiguration();
		config.SSID = ssid;
		config.allowedKeyManagement.get(KeyMgmt.NONE);
		setTetherConfiguration(config);
		isSucess = setTetherEnabled(true);
		// thread can not support the toast 
		// if (isCreateSucess){ 
		// Toast.makeText(context, "create group sucess!!", 
		// Toast.LENGTH_SHORT).show(); 
		// }else { 
		// Toast.makeText(context, "create group failed!!", 
		// Toast.LENGTH_SHORT).show(); 
		// } 
	} 
 
4
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Android WifiConfiguration Questions & Answers:

See Code Examples for Android WifiConfiguration Methods: