List of usage examples for android.net.wifi WifiManager getConnectionInfo
public WifiInfo getConnectionInfo()
From source file:Main.java
public static boolean checkWIFI(Context cxt) { WifiManager wifi = (WifiManager) cxt.getSystemService(Context.WIFI_SERVICE); if ((wifi.isWifiEnabled() == true)) { WifiInfo wifiInf = wifi.getConnectionInfo(); /* Get the MAC ADD of WIFI */ // Commons.MAC_ID = wifiInf.getMacAddress(); return true; } else {/*w w w. j av a 2 s. c o m*/ return false; } }
From source file:Main.java
public static String getWifiIP(Context context) { String ip = null;/*from ww w .j av a2s . com*/ WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); if (wifiManager.isWifiEnabled()) { WifiInfo wifiInfo = wifiManager.getConnectionInfo(); int i = wifiInfo.getIpAddress(); ip = (i & 0xFF) + "." + ((i >> 8) & 0xFF) + "." + ((i >> 16) & 0xFF) + "." + (i >> 24 & 0xFF); } return ip; }
From source file:com.njlabs.amrita.aid.util.Identifier.java
public static String[] getWifiInfo(Context context) { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); int RSSI = wifiManager.getConnectionInfo().getRssi(); String SSID = wifiManager.getConnectionInfo().getSSID().replace("\"", ""); int level = WifiManager.calculateSignalLevel(RSSI, 5); return new String[] { SSID, String.valueOf(level) }; }
From source file:Main.java
public static int getIpAddressInt(Context context) { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); if (wifiManager == null) return 0; WifiInfo info = wifiManager.getConnectionInfo(); return info == null ? 0 : info.getIpAddress(); }
From source file:Main.java
public static boolean isOnWifi(Context context) { WifiManager lWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); return lWifiManager == null ? false : lWifiManager.isWifiEnabled() && lWifiManager.getConnectionInfo() != null && lWifiManager.getConnectionInfo().getIpAddress() != 0; }
From source file:Main.java
public static String getWifiMac(Context context) { String macAddr;/*from w ww .j a va2 s.c o m*/ WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); macAddr = wifiInfo.getMacAddress(); if (TextUtils.isEmpty(macAddr)) { NetworkInterface networkInterface = null; try { networkInterface = NetworkInterface.getByInetAddress(InetAddress.getByName(getIPAddr())); byte[] hardwareAddress = networkInterface.getHardwareAddress(); macAddr = byte2hex(hardwareAddress); } catch (SocketException e) { e.printStackTrace(); } catch (UnknownHostException e) { e.printStackTrace(); } } return macAddr; }
From source file:Main.java
public static String getDeviceInfo(Context context) { try {/*from w w w . j a v a 2s . c om*/ android.telephony.TelephonyManager tm = (android.telephony.TelephonyManager) context .getSystemService(Context.TELEPHONY_SERVICE); String device_id = tm.getDeviceId(); if (TextUtils.isEmpty(device_id)) { android.net.wifi.WifiManager wifi = (android.net.wifi.WifiManager) context .getSystemService(Context.WIFI_SERVICE); device_id = wifi.getConnectionInfo().getMacAddress(); } if (TextUtils.isEmpty(device_id)) { device_id = android.provider.Settings.Secure.getString(context.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID); } return device_id; } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static String getDeviceInfo(Context context) { try {//from ww w .j av a2s. c o m org.json.JSONObject json = new org.json.JSONObject(); android.telephony.TelephonyManager tm = (android.telephony.TelephonyManager) context .getSystemService(Context.TELEPHONY_SERVICE); String device_id = tm.getDeviceId(); android.net.wifi.WifiManager wifi = (android.net.wifi.WifiManager) context .getSystemService(Context.WIFI_SERVICE); String mac = wifi.getConnectionInfo().getMacAddress(); json.put("mac", mac); if (TextUtils.isEmpty(device_id)) { device_id = mac; } if (TextUtils.isEmpty(device_id)) { device_id = android.provider.Settings.Secure.getString(context.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID); } json.put("device_id", device_id); return json.toString(); } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:Main.java
static public String getMacAddress(Context context, ConnectivityManager connMananger) { Log.d(TAG, "getMacAddress"); String macAddress = ""; NetworkInfo info = connMananger.getActiveNetworkInfo(); if (info != null && info.isConnected()) { int type = info.getType(); Log.d(TAG, "connected type = " + type + " name " + info.getTypeName()); if (type == ConnectivityManager.TYPE_WIFI) { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); macAddress = wifiInfo.getMacAddress(); } else if (type == ConnectivityManager.TYPE_ETHERNET || type == ConnectivityManager.TYPE_MOBILE) { String addressFileName = "/sys/class/net/eth0/address"; File addressFile = new File(addressFileName); Log.d(TAG, "1"); if (addressFile.exists()) { Log.d(TAG, "2"); macAddress = readString(addressFile); Log.d(TAG, macAddress);//www .j a va 2 s. co m } else { addressFileName = "/sys/class/net/eth1/address"; addressFile = new File(addressFileName); if (addressFile.exists()) { macAddress = readString(addressFile); Log.d(TAG, macAddress); } } } else { //other type; } } return macAddress; }
From source file:com.njlabs.amrita.aid.util.Identifier.java
public static boolean isConnectedToAmrita(Context context) { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); if (wifiManager != null) { String SSID = wifiManager.getConnectionInfo().getSSID().replace("\"", "").trim(); return SSID.contentEquals("Amrita"); }/*from w w w. j av a2 s.c om*/ return false; }