List of usage examples for android.net.wifi WifiManager getConnectionInfo
public WifiInfo getConnectionInfo()
From source file:org.mythtv.client.ui.MainMenuFragment.java
/** * @throws IOException/* ww w . j a v a 2s . co m*/ */ private void startProbe() throws IOException { Log.v(TAG, "startProbe : enter"); if (zeroConf != null) { stopProbe(); } // figure out our wifi address, otherwise bail WifiManager wifi = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE); WifiInfo wifiinfo = wifi.getConnectionInfo(); int intaddr = wifiinfo.getIpAddress(); byte[] byteaddr = new byte[] { (byte) (intaddr & 0xff), (byte) (intaddr >> 8 & 0xff), (byte) (intaddr >> 16 & 0xff), (byte) (intaddr >> 24 & 0xff) }; InetAddress addr = InetAddress.getByAddress(byteaddr); Log.d(TAG, "startProbe : wifi address=" + addr.toString()); // start multicast lock mLock = wifi.createMulticastLock("mythtv_lock"); mLock.setReferenceCounted(true); mLock.acquire(); zeroConf = JmDNS.create(addr, HOSTNAME); zeroConf.addServiceListener(MYTHTV_FRONTEND_TYPE, this); Log.v(TAG, "startProbe : exit"); }
From source file:org.fdroid.fdroid.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; }/*from w w w. ja v a 2 s . c o m*/ 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(); } // TODO we should help the user to the right thing here, // instead of just showing a message! } }
From source file:com.sentaroh.android.TaskAutomation.TaskExecutor.java
final static public boolean setWifiDisableSsid(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util, TaskResponse taskResponse, ActionResponse ar) { WifiManager wm = (WifiManager) taskMgrParms.context.getSystemService(Context.WIFI_SERVICE); int nwid = wm.getConnectionInfo().getNetworkId(); if (envParms.isWifiConnected()) { if (!envParms.wifiSsid.equals(EnvironmentParms.WIFI_DIRECT_SSID)) { wm.disableNetwork(nwid);// w ww. j ava 2s. c o m ar.action_resp = ActionResponse.ACTION_SUCCESS; ar.resp_msg_text = ""; return true; } else { ar.action_resp = ActionResponse.ACTION_WARNING; ar.resp_msg_text = "Can not disabled, WiFi is connected to WiFi-Direct"; return false; } } ar.action_resp = ActionResponse.ACTION_WARNING; ar.resp_msg_text = "Wifi not connected"; return false; }
From source file:com.sentaroh.android.TaskAutomation.TaskExecutor.java
final static public boolean setWifiRemoveSsid(TaskManagerParms taskMgrParms, EnvironmentParms envParms, CommonUtilities util, TaskResponse taskResponse, ActionResponse ar) { WifiManager wm = (WifiManager) taskMgrParms.context.getSystemService(Context.WIFI_SERVICE); int nwid = wm.getConnectionInfo().getNetworkId(); if (envParms.isWifiConnected()) { if (!envParms.wifiSsid.equals(EnvironmentParms.WIFI_DIRECT_SSID)) { wm.removeNetwork(nwid);/* ww w .j a v a2 s . c om*/ ar.action_resp = ActionResponse.ACTION_SUCCESS; ar.resp_msg_text = ""; return true; } else { ar.action_resp = ActionResponse.ACTION_WARNING; ar.resp_msg_text = "Can not removed, WiFi is connected to WiFi-Direct"; return false; } } ar.action_resp = ActionResponse.ACTION_WARNING; ar.resp_msg_text = "Wifi not connected"; return false; }
From source file:com.sentaroh.android.SMBSync2.CommonUtilities.java
public String getConnectedWifiSsid() { String ret = ""; WifiManager mWifi = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); String ssid = ""; if (mWifi.isWifiEnabled()) { ssid = mWifi.getConnectionInfo().getSSID(); if (ssid != null && !ssid.equals("0x") && !ssid.equals("<unknown ssid>") && !ssid.equals("")) ret = ssid;//from ww w. j a va 2 s.c om // Log.v("","ssid="+ssid); } addDebugMsg(2, "I", "getConnectedWifiSsid WifiEnabled=" + mWifi.isWifiEnabled() + ", SSID=" + ssid + ", result=" + ret); return ret; }
From source file:cn.apputest.ctria.section2.Lucha2Activity.java
public String getLocalIPAddress() { // ?wifi?/*from ww w .j ava 2 s . c o m*/ WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); // wifi?? if (!wifiManager.isWifiEnabled()) { String ip = getLocalIpAddressGPRS(); return ip; } else { WifiInfo wifiInfo = wifiManager.getConnectionInfo(); int ipAddress = wifiInfo.getIpAddress(); String ip = intToIp(ipAddress); return ip; } }
From source file:de.ub0r.android.wifibarcode.WifiBarcodeActivity.java
/** * Load wifi configurations.// w w w . j ava 2 s. co m */ private void loadWifiConfigurations() { WifiAdapter adapter = (WifiAdapter) mSpConfigs.getAdapter(); WifiManager wm = (WifiManager) getSystemService(WIFI_SERVICE); List<WifiConfiguration> wcs = wm.getConfiguredNetworks(); String currentSSID = wm.getConnectionInfo().getSSID(); Log.d(TAG, "currentSSID=", currentSSID); WifiConfiguration custom = new WifiConfiguration(); custom.SSID = getString(R.string.custom); adapter.clear(); adapter.add(custom); flushWifiPasswords(); Log.d(TAG, "#wcs=", wcs == null ? "null" : wcs.size()); if (wcs != null) { int selected = -1; for (WifiConfiguration wc : wcs) { adapter.add(wc, getWifiPassword(wc)); Log.d(TAG, "wc.SSID=", wc.SSID); if (mFirstLoad && currentSSID != null && currentSSID.equals(wc.SSID)) { selected = adapter.getCount() - 1; Log.d(TAG, "selected=", selected); } } if (selected > 0) { // mFirstLoad == true mSpConfigs.setSelection(selected); } mFirstLoad = false; } }
From source file:org.universAAL.android.services.MiddlewareService.java
/** * Sets the current active WiFi connection as the network where "our" AAL * Space is located.//from ww w. j a v a 2 s . c om */ private void thisIsOurWifi() { // if (isWifiOn()) { WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); String networkId = wifiInfo.getSSID(); PreferenceManager.getDefaultSharedPreferences(this).edit().putString(AppConstants.MY_WIFI, networkId) .commit(); Log.i(TAG, "Setting home space Wifi: " + networkId); // } }
From source file:org.universAAL.android.services.MiddlewareService.java
/** * Check what is the current connection status of WiFi. * /*from w ww .j av a 2s .c om*/ * @return Constant representing the status. */ private int checkWifi() { // if (isWifiOn()) { WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); if (wifiInfo.getNetworkId() == -1) { //No network actually Log.i(TAG, "WIFI CHECK: Wifi is not on"); return AppConstants.WIFI_OFF; } String networkId = wifiInfo.getSSID(); String home = PreferenceManager.getDefaultSharedPreferences(this).getString(AppConstants.MY_WIFI, AppConstants.NO_WIFI); Log.i(TAG, "WIFI CHECK: Evaluating: " + networkId); if (home.equals(AppConstants.NO_WIFI)) { Log.i(TAG, "WIFI CHECK: We still do not have a home wifi, maybe this one will be?"); return AppConstants.WIFI_NOTSET; } else if (networkId.equals(home)) { Log.i(TAG, "WIFI CHECK: We have a home wifi, and we are in it!"); return AppConstants.WIFI_HOME; } else { Log.i(TAG, "WIFI CHECK: We have a home wifi, but it is not this one. If you want it to be, clear app data"); return AppConstants.WIFI_STRANGER; } // } // Log.i(TAG, "WIFI CHECK: Wifi is not on"); // return AppConstants.WIFI_OFF; }