Search in sources :

Example 61 with WifiManager

use of android.net.wifi.WifiManager in project weiui by kuaifan.

the class DeviceUtils method getMacAddressByWifiInfo.

@SuppressLint({ "HardwareIds", "MissingPermission" })
private static String getMacAddressByWifiInfo() {
    try {
        Context context = Utils.getApp().getApplicationContext();
        WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        if (wifi != null) {
            WifiInfo info = wifi.getConnectionInfo();
            if (info != null)
                return info.getMacAddress();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return "02:00:00:00:00:00";
}
Also used : Context(android.content.Context) WifiManager(android.net.wifi.WifiManager) WifiInfo(android.net.wifi.WifiInfo) SocketException(java.net.SocketException) SuppressLint(android.annotation.SuppressLint)

Example 62 with WifiManager

use of android.net.wifi.WifiManager in project fdroidclient by f-droid.

the class ManageReposActivity method checkIfNewRepoOnSameWifi.

private void checkIfNewRepoOnSameWifi(NewRepoConfig newRepo) {
    // if this is a local repo, check we're on the same wifi
    if (!TextUtils.isEmpty(newRepo.getBssid())) {
        WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
        WifiInfo wifiInfo = wifiManager.getConnectionInfo();
        String bssid = wifiInfo.getBSSID();
        if (TextUtils.isEmpty(bssid)) {
            /* not all devices have wifi */
            return;
        }
        bssid = bssid.toLowerCase(Locale.ENGLISH);
        String newRepoBssid = Uri.decode(newRepo.getBssid()).toLowerCase(Locale.ENGLISH);
        if (!bssid.equals(newRepoBssid)) {
            String msg = String.format(getString(R.string.not_on_same_wifi), newRepo.getSsid());
            Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
        }
    // TODO we should help the user to the right thing here,
    // instead of just showing a message!
    }
}
Also used : WifiManager(android.net.wifi.WifiManager) WifiInfo(android.net.wifi.WifiInfo)

Example 63 with WifiManager

use of android.net.wifi.WifiManager in project fdroidclient by f-droid.

the class SwapWorkflowActivity method promptToSetupWifiAP.

private void promptToSetupWifiAP() {
    WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    WifiApControl ap = WifiApControl.getInstance(this);
    wifiManager.setWifiEnabled(false);
    if (!ap.enable()) {
        Log.e(TAG, "Could not enable WiFi AP.");
    // TODO: Feedback to user?
    } else {
        Utils.debugLog(TAG, "WiFi AP enabled.");
    // TODO: Seems to be broken some times...
    }
}
Also used : WifiManager(android.net.wifi.WifiManager) WifiApControl(cc.mvdan.accesspoint.WifiApControl)

Example 64 with WifiManager

use of android.net.wifi.WifiManager in project mapbox-plugins-android by mapbox.

the class PlaceAutocompleteFragmentTest method offline_doesShowCorrectViewWhenDeviceOffline.

// 
// Offline state test
// 
// Note, device should also not have data enabled for test to pass. Cannot currently find a way to
// disable this however.
@Test
public void offline_doesShowCorrectViewWhenDeviceOffline() throws Exception {
    WifiManager wifi = (WifiManager) activityRule.getActivity().getSystemService(Context.WIFI_SERVICE);
    wifi.setWifiEnabled(false);
    onView(withId(R.id.edittext_search)).perform(typeText("W"));
    onView(withId(R.id.offlineResultView)).check(matches(isDisplayed()));
}
Also used : WifiManager(android.net.wifi.WifiManager) Test(org.junit.Test)

Example 65 with WifiManager

use of android.net.wifi.WifiManager in project mapbox-plugins-android by mapbox.

the class PlaceAutocompleteFragmentTest method offline_doesShowCorrectViewWhenDeviceGoesBackOnline.

@Test
public void offline_doesShowCorrectViewWhenDeviceGoesBackOnline() throws Exception {
    WifiManager wifi = (WifiManager) activityRule.getActivity().getSystemService(Context.WIFI_SERVICE);
    wifi.setWifiEnabled(true);
    onView(withId(R.id.edittext_search)).perform(typeText("W"));
    onView(withId(R.id.offlineResultView)).check(matches(not((isDisplayed()))));
}
Also used : WifiManager(android.net.wifi.WifiManager) Test(org.junit.Test)

Aggregations

WifiManager (android.net.wifi.WifiManager)329 WifiInfo (android.net.wifi.WifiInfo)80 WifiConfiguration (android.net.wifi.WifiConfiguration)76 IOException (java.io.IOException)38 Intent (android.content.Intent)27 SuppressLint (android.annotation.SuppressLint)26 ConnectivityManager (android.net.ConnectivityManager)23 Context (android.content.Context)22 NetworkInfo (android.net.NetworkInfo)21 Test (org.junit.Test)20 AccessPoint (com.android.settingslib.wifi.AccessPoint)17 IntentFilter (android.content.IntentFilter)16 Bundle (android.os.Bundle)16 ArrayList (java.util.ArrayList)16 NetworkPolicyEditor (com.android.settingslib.NetworkPolicyEditor)12 PowerManager (android.os.PowerManager)11 WifiEnterpriseConfig (android.net.wifi.WifiEnterpriseConfig)10 SocketException (java.net.SocketException)10 SharedPreferences (android.content.SharedPreferences)9 Method (java.lang.reflect.Method)9