Android WifiManager - 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 WifiManager class.

This code example shows how to use the following methods:isWifiEnabled
	 *  
	 * @returns {boolean} The status of Wi-Fi in device settings. 
	 */ 
	public boolean isWifiEnabled() { 
		WifiManager wifiManager = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE);
		boolean result = wifiManager.isWifiEnabled();
		Log.d(LOG_TAG, "Wifi enabled: " + result);
		return result;
	} 
	 
	/** 
	 * Requests that the user enable the Wi-Fi in device settings. 
	 */ 
	public void switchToWifiSettings() { 
		Log.d(LOG_TAG, "Switch to Wifi Settings");
		Intent settingsIntent = new Intent(Settings.ACTION_WIFI_SETTINGS);
		ctx.startActivity(settingsIntent);
	} 
	 
	/** 
9
CodeRank
This code example shows how to use the following methods:getConnectionInfo
        WifiManager wifiManager = (WifiManager) application.getSystemService(WIFI_SERVICE);
        WifiInfo wifiInfo = wifiManager.getConnectionInfo();
        shadowOf(wifiInfo).setMacAddress("mac address");
 
        wifiManager = (WifiManager) application.getSystemService(WIFI_SERVICE);
        wifiInfo = wifiManager.getConnectionInfo();
        assertThat(wifiInfo.getMacAddress()).isEqualTo("mac address");
    } 
} 
8
CodeRank
This code example shows how to use the following methods:addNetwork, getConfiguredNetworks, updateNetwork
8
CodeRank
This code example shows how to use the following methods:addNetwork, getConfiguredNetworks, updateNetwork
8
CodeRank
This code example shows how to use the following methods:addNetwork, disconnect, enableNetwork, getConnectionInfo, isWifiEnabled
        serverSocket.close();
        Log.d(TAG, "Server socket closed");
    } 
 
    public void connectToTheGame(String gameName) {
        if(wifiManager.isWifiEnabled()) {
            initialNetworkConfigId = wifiManager.getConnectionInfo().getNetworkId();
        } 
 
        WifiConfiguration wifiConfiguration = new WifiConfiguration();
        wifiConfiguration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
        wifiConfiguration.SSID = "\"" + gameName + "\"";
 
        int netId = wifiManager.addNetwork(wifiConfiguration);
        wifiManager.disconnect();
        wifiManager.enableNetwork(netId, true);
        wifiManager.reconnect();
    } 
 
    public void stopLookingForWiFi() { 

7
CodeRank
This code example shows how to use the following methods:getWifiApConfiguration, setWifiApEnabled
    @Override 
    protected void setUp() throws Exception { 
        super.setUp(); 
        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(); 
    } 
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:disconnect
    @Override 
    public void onReceive(Context c, Intent intent) {
        // if wifi tries to connect while we are sending an MMS, disable it until that message is done sending 
    	WifiManager wifi = (WifiManager) c.getSystemService(Context.WIFI_SERVICE);
        if(!intent.getParcelableExtra(WifiManager.EXTRA_NEW_STATE).toString().equals(SupplicantState.SCANNING)) 
        	wifi.disconnect();
    } 
} 
7
CodeRank
This code example shows how to use the following methods:getConnectionInfo, isWifiEnabled
            setSupplicantStateText(state);
        } 
    } 
 
    private void handleNetworkStateChanged(NetworkInfo networkInfo) {
        if (mWifiManager.isWifiEnabled()) {
            String summary = Summary.get(this, mWifiManager.getConnectionInfo().getSSID(),
                    networkInfo.getDetailedState());
            mNetworkState.setText(summary);
        } 
    } 
 
    private final void updatePingState() { 
        final Handler handler = new Handler();
        // Set all to unknown since the threads will take a few secs to update. 
        mPingIpAddrResult = getResources().getString(R.string.radioInfo_unknown);
        mPingHostnameResult = getResources().getString(R.string.radioInfo_unknown);
        mHttpClientTestResult = getResources().getString(R.string.radioInfo_unknown);
 
        mPingIpAddr.setText(mPingIpAddrResult);
7
CodeRank
This code example shows how to use the following methods:isWifiEnabled
		} 
		return cachedInstance;
	} 
	 
	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);
		} 
7
CodeRank

Related Android WifiManager Questions & Answers:

See Code Examples for Android WifiManager Methods: