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 void setWifiEnable(Context context, boolean sw) { // <uses-permission // android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission> WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); // boolean enabled = wifiManager.isWifiEnabled(); wifiManager.setWifiEnabled(sw);/*www. j a v a2 s . c o m*/ }
From source file:Main.java
public static boolean acquireWifiLock(Context context) { //We only allow backup on wifi connection. Make sure we are connected and if so lock the wifi connection ConnectivityManager connManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo wifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (wifi.isConnected()) { if (wifiLock == null) { WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); wifiLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL, "com.zns.comicdroid.wifilock"); wifiLock.setReferenceCounted(true); wifiLock.acquire();/*from w ww . j a v a2s . c o m*/ } else { wifiLock.acquire(); } return true; } return false; }
From source file:Main.java
public static String getDeviceId(Context context) { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); String uuid = tm.getDeviceId(); if (uuid == null) { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); String mac = wifiManager.getConnectionInfo().getMacAddress(); if (mac == null) throw new IllegalStateException(); return mac; }// w ww . j av a 2s .c om return uuid; }
From source file:alaindc.crowdroid.RadioUtils.java
public static String[] getWifiInfo(Context context) { try {/*w ww. j a va2 s . c o m*/ WifiManager wifiMan = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiMan.getConnectionInfo(); String bssid = wifiInfo.getBSSID(); String ssid = wifiInfo.getSSID(); String signalStrength = String.valueOf(wifiInfo.getRssi()); // Update view Intent senseintent = new Intent(Constants.INTENT_UPDATE_SENSORS); senseintent.putExtra(Constants.INTENT_RECEIVED_DATA_EXTRA_DATA, ssid + " " + signalStrength); LocalBroadcastManager.getInstance(context).sendBroadcast(senseintent); return new String[] { bssid, ssid, signalStrength }; } catch (Exception e) { return new String[] { "", "", "" }; } }
From source file:org.namelessrom.devicecontrol.net.NetworkInfo.java
public static String getWifiIp() { final WifiManager wifiManager = (WifiManager) Application.get().getSystemService(Context.WIFI_SERVICE); int ipAddress = wifiManager.getConnectionInfo().getIpAddress(); if (ByteOrder.nativeOrder().equals(ByteOrder.LITTLE_ENDIAN)) { ipAddress = Integer.reverseBytes(ipAddress); }/*from ww w . j a v a2 s . com*/ final byte[] ipByteArray = BigInteger.valueOf(ipAddress).toByteArray(); String ipAddressString; try { ipAddressString = InetAddress.getByAddress(ipByteArray).getHostAddress(); } catch (UnknownHostException ex) { ipAddressString = "0.0.0.0"; } return ipAddressString; }
From source file:Main.java
public static final String getOblyDevicesID(Context mContext) { String m_szImei = ""; try {/*from w w w . ja v a 2s.c o m*/ TelephonyManager TelephonyMgr = null; TelephonyMgr = (TelephonyManager) mContext.getSystemService(Activity.TELEPHONY_SERVICE); m_szImei = TelephonyMgr.getDeviceId(); } catch (Exception ex) { ex.printStackTrace(); } String m_szDevIDShort = null; try { m_szDevIDShort = "35" + //we make this look like a valid IMEI Build.BOARD.length() % 10 + Build.BRAND.length() % 10 + Build.CPU_ABI.length() % 10 + Build.DEVICE.length() % 10 + Build.DISPLAY.length() % 10 + Build.HOST.length() % 10 + Build.ID.length() % 10 + Build.MANUFACTURER.length() % 10 + Build.MODEL.length() % 10 + Build.PRODUCT.length() % 10 + Build.TAGS.length() % 10 + Build.TYPE.length() % 10 + Build.USER.length() % 10; //13 digits } catch (Exception ex) { ex.printStackTrace(); } String m_szAndroidID = ""; try { m_szAndroidID = ""; Settings.Secure.getString(mContext.getContentResolver(), Settings.Secure.ANDROID_ID); } catch (Exception ex) { ex.printStackTrace(); } String m_szWLANMAC = ""; try { WifiManager wm = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); m_szWLANMAC = wm.getConnectionInfo().getMacAddress(); } catch (Exception ex) { ex.printStackTrace(); } String m_szBTMAC = null; try { BluetoothAdapter m_BluetoothAdapter = null; // Local Bluetooth adapter m_BluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); m_szBTMAC = m_BluetoothAdapter.getAddress(); } catch (Exception ex) { ex.printStackTrace(); } String m_szLongID = m_szImei + m_szDevIDShort + m_szAndroidID + m_szWLANMAC + m_szBTMAC; // compute md5 MessageDigest m = null; try { m = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } m.update(m_szLongID.getBytes(), 0, m_szLongID.length()); // get md5 bytes byte p_md5Data[] = m.digest(); // create a hex string String m_szUniqueID = new String(); for (int i = 0; i < p_md5Data.length; i++) { int b = (0xFF & p_md5Data[i]); // if it is a single digit, make sure it have 0 in front (proper padding) if (b <= 0xF) m_szUniqueID += "0"; // add number to string m_szUniqueID += Integer.toHexString(b); } // hex string to uppercase m_szUniqueID = m_szUniqueID.toUpperCase(); return m_szUniqueID; }
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 {/*from ww w . ja v a2s .com*/ 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:Main.java
/** * @Thach @SK29// w w w . j ava 2s .co m * @Init MAC address and save to preference * @param context * @return */ private static String initMacAddress(Context context) { // INIT macAddress String macAddress; WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); if (wifiManager.isWifiEnabled()) { // WIFI ALREADY ENABLED. GRAB THE MAC ADDRESS HERE WifiInfo info = wifiManager.getConnectionInfo(); macAddress = info.getMacAddress(); } else { // ENABLE THE WIFI FIRST wifiManager.setWifiEnabled(true); // WIFI IS NOW ENABLED. GRAB THE MAC ADDRESS HERE WifiInfo info = wifiManager.getConnectionInfo(); macAddress = info.getMacAddress(); // NOW DISABLE IT AGAIN wifiManager.setWifiEnabled(false); } if (macAddress == null) { macAddress = android.os.Build.ID; } return macAddress; }
From source file:com.macleod2486.androidswissknife.components.Wifi.java
public Wifi(FragmentActivity activity) { this.activity = activity; this.wifiManager = (WifiManager) this.activity.getSystemService(Context.WIFI_SERVICE); }
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) }; }