List of usage examples for android.net.wifi WifiManager getConnectionInfo
public WifiInfo getConnectionInfo()
From source file:mf.sync.utils.SessionInfo.java
@SuppressWarnings("deprecation") public static InetAddress getWifiAddress(Context c) { if (c == null) throw new RuntimeException("Context is null"); WifiManager wm = (WifiManager) c.getSystemService(Context.WIFI_SERVICE); try {//ww w. jav a 2 s . co m return InetAddress.getByName(Formatter.formatIpAddress(wm.getConnectionInfo().getIpAddress())); } catch (UnknownHostException e) { Log.e("sync utils", "cannot get wifi address, returning null..."); } return null; }
From source file:com.tencent.wetest.common.util.DeviceUtil.java
/** * ?MAC?//from ww w .j a v a 2s .c o m * @param ctx * @return */ public static String getMacAddr(Context ctx) { WifiManager wifiManager = (WifiManager) ctx.getSystemService(Service.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); return wifiInfo.getMacAddress(); }
From source file:com.google.android.libraries.cast.companionlibrary.utils.Utils.java
/** * Returns the SSID of the wifi connection, or <code>null</code> if there is no wifi. *///from w w w . j a va 2 s.com public static String getWifiSsid(Context context) { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); if (wifiInfo != null) { return wifiInfo.getSSID(); } return null; }
From source file:ca.frozen.curlingtv.classes.Utils.java
public static String getWifiName() { String ssid = ""; WifiManager manager = (WifiManager) App.getContext().getSystemService(Context.WIFI_SERVICE); if (manager.isWifiEnabled()) { WifiInfo wifiInfo = manager.getConnectionInfo(); if (wifiInfo != null) { NetworkInfo.DetailedState state = WifiInfo.getDetailedStateOf(wifiInfo.getSupplicantState()); if (state == NetworkInfo.DetailedState.CONNECTED || state == NetworkInfo.DetailedState.OBTAINING_IPADDR) { ssid = wifiInfo.getSSID(); if (ssid == null) ssid = ""; ssid = ssid.replaceAll("^\"|\"$", ""); }//from w w w . ja v a 2s . co m } } return ssid; }
From source file:org.basdroid.common.NetworkUtils.java
public static String getMacAddress(Context context) { WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); return wm.getConnectionInfo().getMacAddress(); }
From source file:com.wiyun.engine.network.Network.java
static boolean isWifiConnected() { Context context = Director.getInstance().getContext(); if (context.checkCallingOrSelfPermission( android.Manifest.permission.ACCESS_WIFI_STATE) == PackageManager.PERMISSION_GRANTED) { WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); if (wm != null) { WifiInfo info = wm.getConnectionInfo(); return info != null && info.getSupplicantState() == SupplicantState.COMPLETED; } else {/*w w w .j ava2 s . c o m*/ return false; } } else { Log.w("libwiengine", "you need add ACCESS_WIFI_STATE permission"); return false; } }
From source file:org.basdroid.common.NetworkUtils.java
/** * Wi-fi AP //from w w w. j a v a 2 s. co m */ public static WifiInfo getCurrentWifiInfo(Context context) { WifiInfo wifiInfo = null; if (isConnectedWifi(context)) { final WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); wifiInfo = wifiManager.getConnectionInfo(); } return wifiInfo; }
From source file:org.basdroid.common.NetworkUtils.java
public static String getMacAddressFromNetworkInterface(final Context context) { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); int ipAddress = wifiInfo.getIpAddress(); // Convert little-endian to big-endianif needed if (ByteOrder.nativeOrder().equals(ByteOrder.LITTLE_ENDIAN)) { ipAddress = Integer.reverseBytes(ipAddress); }/* ww w . java 2 s . c o m*/ byte[] bytes = BigInteger.valueOf(ipAddress).toByteArray(); String result; try { InetAddress addr = InetAddress.getByAddress(bytes); NetworkInterface netInterface = NetworkInterface.getByInetAddress(addr); Log.d(TAG, "Wifi netInterface.getName() = " + netInterface.getName()); byte[] mac = netInterface.getHardwareAddress(); if (mac == null || mac.length == 0) return ""; StringBuilder buf = new StringBuilder(); for (int idx = 0; idx < mac.length; idx++) { buf.append(String.format("%02X:", mac[idx])); } if (buf.length() > 0) buf.deleteCharAt(buf.length() - 1); return buf.toString(); } catch (UnknownHostException ex) { Log.e(TAG, "getMacAddressFromNetworkInterface() Unknown host.", ex); result = null; } catch (SocketException ex) { Log.e(TAG, "getMacAddressFromNetworkInterface() Socket exception.", ex); result = null; } catch (Exception ex) { Log.e(TAG, "getMacAddressFromNetworkInterface() Exception.", ex); result = null; } return result; }
From source file:com.google.sample.castcompanionlibrary.utils.Utils.java
/** * Returns the SSID of the wifi connection, or <code>null</code> if there is no wifi. * * @param context// w ww . j av a 2 s . c o m * @return */ public static String getWifiSsid(Context context) { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); if (null != wifiInfo) { return wifiInfo.getSSID(); } return null; }
From source file:com.otaupdater.utils.Utils.java
public static String getDeviceID(Context ctx) { if (deviceID != null) return deviceID; deviceID = ((TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId(); if (deviceID == null) { WifiManager wm = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE); if (wm.isWifiEnabled()) { deviceID = wm.getConnectionInfo().getMacAddress(); } else {//from w w w.j av a 2 s . c o m //fallback to ANDROID_ID - gets reset on data wipe, but it's better than nothing deviceID = Settings.Secure.getString(ctx.getContentResolver(), Settings.Secure.ANDROID_ID); } } deviceID = md5(deviceID); return deviceID; }