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:com.mobilyzer.util.PhoneUtils.java
public int getWifiRSSI() { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); if (wifiInfo != null) { return wifiInfo.getRssi(); }// w w w . j a va 2s .com return -1; }
From source file:edu.cmu.mpcs.dashboard.TagViewer.java
private String wifiSetting(String settingString) { /*// www. j a va 2 s .c om * Enable/Disable wifi */ if (settingString.contains("wifi")) { WifiManager wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE); if (settingString.contains("wifi:On")) { wifiManager.setWifiEnabled(true); return ("Wifi turned On\n"); } else { wifiManager.setWifiEnabled(false); return ("Wifi turned Off\n"); } } return (""); }
From source file:org.brandroid.openmanager.fragments.DialogHandler.java
public static String getNetworkInfo(Context c) { String ret = getNetworkInterfaces(); ConnectivityManager conman = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE); if (conman == null) ret += "No Connectivity?\n"; else {/* w w w . j a v a 2 s . c o m*/ ret += "Connectivity Info:\n" + conman.toString() + "\n"; for (NetworkInfo ni : conman.getAllNetworkInfo()) { if (!ni.isAvailable()) continue; ret += "Network [" + ni.getTypeName() + "]: " + getNetworkInfoInfo(ni) + "\n"; } } try { WifiManager wifi = (WifiManager) c.getSystemService(Context.WIFI_SERVICE); if (wifi == null) ret += "No wifi\n"; else { ret += "Wifi Info:\n" + wifi.toString() + "\n"; ret += "Status: " + (wifi.isWifiEnabled() ? "ENABLED" : "DISABLED") + "\n"; ret += "ip=" + getReadableIP(wifi.getConnectionInfo().getIpAddress()) + "/ " + "mac=" + wifi.getConnectionInfo().getMacAddress() + "/ " + "b=" + wifi.getConnectionInfo().getBSSID() + "/ " + "s=" + wifi.getConnectionInfo().getSSID(); DhcpInfo dh = wifi.getDhcpInfo(); if (dh == null) ret += "No DHCP\n"; else { ret += "IP: " + getReadableIP(dh.ipAddress) + "\n"; ret += "Gateway: " + getReadableIP(dh.gateway) + "\n"; ret += "DNS: " + getReadableIP(dh.dns1) + " " + getReadableIP(dh.dns2) + "\n"; } } } catch (SecurityException sec) { ret += "No Wifi permissions.\n"; } return ret; }
From source file:com.landenlabs.all_devtool.NetFragment.java
private void clean_networks() { StringBuilder sb = new StringBuilder(); final WifiManager wifiMgr = (WifiManager) getContext().getApplicationContext() .getSystemService(Context.WIFI_SERVICE); if (wifiMgr != null && wifiMgr.isWifiEnabled() && wifiMgr.getDhcpInfo() != null) { try {/*from www. j a va 2 s . c o m*/ List<WifiConfiguration> listWifiCfg = wifiMgr.getConfiguredNetworks(); for (WifiConfiguration wifiCfg : listWifiCfg) { if (wifiCfg.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.NONE)) { // Remove network connections with no Password. if (wifiMgr.removeNetwork(wifiCfg.networkId)) { sb.append(wifiCfg.SSID); sb.append("\n"); } } } } catch (Exception ex) { } } if (sb.length() != 0) { Toast.makeText(this.getContext(), "Removed Networks: " + sb.toString(), Toast.LENGTH_LONG).show(); } }
From source file:com.jtechme.apphub.views.ManageReposActivity.java
private void checkIfNewRepoOnSameWifi(NewRepoConfig newRepo) { // if this is a local repo, check we're on the same wifi if (!TextUtils.isEmpty(newRepo.getBssid())) { WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); String bssid = wifiInfo.getBSSID(); if (TextUtils.isEmpty(bssid)) /* not all devices have wifi */ return; bssid = bssid.toLowerCase(Locale.ENGLISH); String newRepoBssid = Uri.decode(newRepo.getBssid()).toLowerCase(Locale.ENGLISH); if (!bssid.equals(newRepoBssid)) { String msg = String.format(getString(R.string.not_on_same_wifi), newRepo.getSsid()); Toast.makeText(this, msg, Toast.LENGTH_LONG).show(); }// w w w .j a va2 s . c o m // TODO we should help the user to the right thing here, // instead of just showing a message! } }
From source file:at.alladin.rmbt.android.util.InformationCollector.java
/** * Lazily initializes the network managers. * /*w ww.jav a2 s. c o m*/ * As a side effect, assigns connectivityManager and telephonyManager. */ private synchronized void initNetwork() { if (connManager == null) { final ConnectivityManager tryConnectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); final TelephonyManager tryTelephonyManager = (TelephonyManager) context .getSystemService(Context.TELEPHONY_SERVICE); final WifiManager tryWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); // Assign to member vars only after all the get calls succeeded, connManager = tryConnectivityManager; telManager = tryTelephonyManager; wifiManager = tryWifiManager; if (Build.VERSION.SDK_INT >= 18) { telManagerSupport = new TelephonyManagerV18(telManager); } else { telManagerSupport = new TelephonyManagerPreV18(telManager); } // Some interesting info to look at in the logs //final NetworkInfo[] infos = connManager.getAllNetworkInfo(); //for (final NetworkInfo networkInfo : infos) // Log.i(DEBUG_TAG, "Network: " + networkInfo); } assert connManager != null; assert telManager != null; assert wifiManager != null; }
From source file:com.thejoshwa.ultrasonic.androidapp.util.Util.java
public static WifiManager.WifiLock createWifiLock(Context context, String tag) { WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); return wm.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, tag); }
From source file:org.metawatch.manager.Monitors.java
private static void createWifiReceiver(final Context context) { if (wifiReceiver != null) return;/*from w ww. j a v a2 s . c o m*/ WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo info = wm.getConnectionInfo(); if (info != null) SignalData.wifiBars = 1 + WifiManager.calculateSignalLevel(info.getRssi(), 4); wifiReceiver = new BroadcastReceiver() { int wifiBars = 0; @Override public void onReceive(Context c, Intent intent) { String action = intent.getAction(); if (action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) { if (intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_UNKNOWN) != WifiManager.WIFI_STATE_ENABLED) { wifiBars = 0; } } else if (action.equals(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION)) { if (!intent.getBooleanExtra(WifiManager.EXTRA_SUPPLICANT_CONNECTED, false)) { wifiBars = 0; } } else if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) { NetworkInfo netInfo = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO); if (netInfo.getState() != NetworkInfo.State.CONNECTED) { wifiBars = 0; } else { WifiInfo wifiInfo = intent.getParcelableExtra(WifiManager.EXTRA_WIFI_INFO); if (wifiInfo == null) { wifiBars = 0; } else { wifiBars = 1 + WifiManager.calculateSignalLevel(wifiInfo.getRssi(), 4); } } } else if (action.equals(WifiManager.RSSI_CHANGED_ACTION)) { final int newRssi = intent.getIntExtra(WifiManager.EXTRA_NEW_RSSI, -200); wifiBars = 1 + WifiManager.calculateSignalLevel(newRssi, 4); } if (wifiBars != SignalData.wifiBars) { SignalData.wifiBars = wifiBars; Idle.updateIdle(context, true); } } }; IntentFilter f = new IntentFilter(); f.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION); f.addAction(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION); f.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION); f.addAction(WifiManager.RSSI_CHANGED_ACTION); context.registerReceiver(wifiReceiver, f); }
From source file:net.ustyugov.jtalk.service.JTalkService.java
@Override public void onCreate() { configure();/*from www. j a va 2 s . co m*/ js = this; prefs = PreferenceManager.getDefaultSharedPreferences(this); iconPicker = new IconPicker(this); // updateReceiver = new BroadcastReceiver() { // @Override // public void onReceive(Context arg0, Intent arg1) { // updateWidget(); // } // }; // registerReceiver(updateReceiver, new IntentFilter(Constants.UPDATE)); connectionReceiver = new ChangeConnectionReceiver(); registerReceiver(connectionReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); screenStateReceiver = new ScreenStateReceiver(); registerReceiver(new ScreenStateReceiver(), new IntentFilter(Intent.ACTION_SCREEN_ON)); registerReceiver(new ScreenStateReceiver(), new IntentFilter(Intent.ACTION_SCREEN_OFF)); Intent i = new Intent(this, RosterActivity.class); i.setAction(Intent.ACTION_MAIN); i.addCategory(Intent.CATEGORY_LAUNCHER); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, i, 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this); mBuilder.setSmallIcon(R.drawable.stat_offline); mBuilder.setContentTitle(getString(R.string.app_name)); mBuilder.setContentIntent(contentIntent); startForeground(Notify.NOTIFICATION, mBuilder.build()); WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, "jTalk"); PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "jTalk"); started = true; Cursor cursor = getContentResolver().query(JTalkProvider.ACCOUNT_URI, null, AccountDbHelper.ENABLED + " = '" + 1 + "'", null, null); if (cursor != null && cursor.getCount() > 0) { connect(); cursor.close(); } }