List of usage examples for android.content Context WIFI_SERVICE
String WIFI_SERVICE
To view the source code for android.content Context WIFI_SERVICE.
Click Source Link
From source file:Main.java
/** * Returns MAC address of WiFi module.//ww w. j a v a2s. co m * * @param context - used to get WiFi manager */ public static String getMacAddress(Context context) { final WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); final WifiInfo wifiInfo = wifiManager.getConnectionInfo(); if (wifiInfo == null) return null; return wifiInfo.getMacAddress().toUpperCase(); }
From source file:Main.java
public static String getMacAddress(Context context) { if (TextUtils.isEmpty(macAddress)) { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); if (wifiInfo != null) { macAddress = wifiInfo.getMacAddress(); return macAddress; }/*from w w w . ja va2 s . com*/ } return macAddress; }
From source file:Main.java
/** * <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> *///from w w w . j ava 2 s .c o m public static WifiInfo getConnectionWifi(@NonNull Context context) { WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); return wifi.getConnectionInfo(); }
From source file:Main.java
public static void getScanWifiResults(Context context) { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); List<ScanResult> wifiResults = wifiManager.getScanResults(); for (ScanResult wifi : wifiResults) { // LogUtil.log(TAG, Log.DEBUG, wifi.toString()); }/*w ww .ja v a 2s . c o m*/ TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); // LogUtil.log(TAG, Log.DEBUG, TelephonyManager.PHONE_TYPE_GSM + "----" + tm.getPhoneType()); List<NeighboringCellInfo> cellResults = tm.getNeighboringCellInfo(); for (NeighboringCellInfo cell : cellResults) { // LogUtil.log(TAG, Log.DEBUG, cell.getCid() + "-" + cell.getLac() + "-" + cell.getRssi() + "-" + cell.getPsc() // + "-" + cell.getNetworkType()); } // LogUtil.log(TAG, Log.DEBUG, getProviderName(context).getText()); }
From source file:Main.java
/** * Returns SSID of Wifi hotspot device connected with. * @param context//from w ww .j a v a 2 s. c o m * @return */ public static String getCurrentWifiConnectionSSID(Context context) { final WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); final WifiInfo wifiInfo = wifiManager.getConnectionInfo(); if (wifiInfo == null) return null; String ssid = wifiInfo.getSSID(); if (android.os.Build.VERSION.SDK_INT >= 16) { if (ssid.startsWith("\"") && ssid.endsWith("\"")) { ssid = ssid.substring(1, ssid.length() - 1); } } return ssid; }
From source file:Main.java
public static int getWifiState(Context context) throws Exception { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); if (wifiManager != null) { return wifiManager.getWifiState(); } else {/* www . j a v a 2s .co m*/ throw new Exception("wifi device not found!"); } }
From source file:Main.java
public static void lockWifi(Context context, String lockStr) { if (wifiManager == null) { wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); multicastLock = wifiManager.createMulticastLock(lockStr + "multicast_lock"); multicastLock.acquire();/* w w w . j a v a 2s.co m*/ wifiLock = wifiManager.createWifiLock(lockStr + "wifi_lock"); wifiLock.acquire(); } }
From source file:Main.java
/** * Checks if is wifi./* w ww . j av a 2 s . com*/ * * @param ctx * the ctx * @return true, if is wifi */ public static boolean isWifi(final Context ctx) { WifiManager wm = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE); WifiInfo wi = wm.getConnectionInfo(); if (wi != null && (WifiInfo.getDetailedStateOf(wi.getSupplicantState()) == DetailedState.OBTAINING_IPADDR || WifiInfo.getDetailedStateOf(wi.getSupplicantState()) == DetailedState.CONNECTED)) { return true; } return false; }
From source file:Main.java
static public Boolean toggleWifi(Context context, Boolean enable) { return toggleWifi((WifiManager) context.getSystemService(Context.WIFI_SERVICE), enable); }
From source file:Main.java
public static String getDhcpIpString(Context mContext) { WifiManager mWifiManager;//from ww w . ja v a 2 s . c o m String broadcastIp = null; mWifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); if (mWifiManager.isWifiEnabled()) { DhcpInfo myDhcpInfo = mWifiManager.getDhcpInfo(); if (myDhcpInfo == null) { Toast.makeText(mContext, "can not get dhcp info", Toast.LENGTH_SHORT).show(); return null; } else { try { broadcastIp = getBroadcastAddress(myDhcpInfo).getHostAddress(); } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } } return broadcastIp; } return null; }