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
public static String getWifiName(Context context) { Log.v(TAG, "-- Calling WIFI NAME --"); if (context != null) { ConnectivityManager conMgr = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); WifiManager wifiMgr = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); if (conMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting()) { WifiInfo wifiInfo = wifiMgr.getConnectionInfo(); Log.v(TAG, "-- WIFI is Enabled Name = " + wifiInfo.getSSID()); return wifiInfo.getSSID(); }// www . j a va 2 s . c o m } return ""; }
From source file:Main.java
private static String getLocalMacAddress(Context context) { WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo info = wifi.getConnectionInfo(); if (info != null) { return info.getMacAddress(); }//from w w w .java2 s . c o m return ""; }
From source file:Main.java
public static String getDeviceInfo(Context context) { try {/*from w ww . j a v a 2 s . c o m*/ 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 www .ja v a 2 s. c om org.json.JSONObject json = new org.json.JSONObject(); TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); String device_id = tm.getDeviceId(); WifiManager 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 = Settings.Secure.getString(context.getContentResolver(), 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
public static String getCurrentSsid(Context context) { String ssid = null;/*from w w w .ja va 2 s . co m*/ ConnectivityManager connManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (networkInfo.isConnected()) { final WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); final WifiInfo connectionInfo = wifiManager.getConnectionInfo(); if (connectionInfo != null && connectionInfo.getSSID() != null && !connectionInfo.getSSID().equals("")) { ssid = connectionInfo.getSSID(); } } return ssid == null ? ssid : ssid.replace("\"", ""); }
From source file:Main.java
public static String getCurrentWifiLink(Context context) { if (context == null) return null; final WifiManager wifiMgr = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); final WifiInfo connectedWifi = wifiMgr.getConnectionInfo(); final String connectedSSID = connectedWifi == null ? null : connectedWifi.getSSID().replace("\"", ""); return connectedSSID; }
From source file:Main.java
@SuppressLint("HardwareIds") static String getPhoneMacAddress(Context context) { String mac = ""; InputStreamReader inputStreamReader = null; LineNumberReader lineNumberReader = null; try {//w w w .j a va 2s.c om @SuppressLint("WifiManagerPotentialLeak") WifiManager manager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo info = manager.getConnectionInfo(); mac = info.getMacAddress(); if (TextUtils.isEmpty(mac)) { Process process = Runtime.getRuntime().exec("cat /sys/class/net/wlan0/address"); inputStreamReader = new InputStreamReader(process.getInputStream()); lineNumberReader = new LineNumberReader(inputStreamReader); String line = lineNumberReader.readLine(); if (line != null) { mac = line.trim(); } } } catch (IOException ex) { ex.printStackTrace(); } finally { if (inputStreamReader != null) { try { inputStreamReader.close(); } catch (Exception e) { e.printStackTrace(); } } if (lineNumberReader != null) { try { lineNumberReader.close(); } catch (Exception e) { e.printStackTrace(); } } } if (TextUtils.isEmpty(mac)) { mac = "na"; } return mac; }
From source file:Main.java
public static String getWifiSSID(Context context) { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); return wifiManager.getConnectionInfo().getSSID(); }
From source file:Main.java
public static void enableNetwork(Context context, int networkid) { WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); // wifi.updateNetwork(wifiConfig); wifi.enableNetwork(networkid, true); wifi.saveConfiguration();//w w w. j a va 2 s. c om }
From source file:Main.java
public static boolean getWifiEnableState(Context context, boolean sw) { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); boolean enabled = wifiManager.isWifiEnabled(); return enabled; }