List of usage examples for android.net.wifi WifiManager getConnectionInfo
public WifiInfo getConnectionInfo()
From source file:com.adamkruger.myipaddressinfo.NetworkInfoFragment.java
private void refreshData() { Context context = getActivity(); ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); mNetworkInfo = connectivityManager.getActiveNetworkInfo(); mNetworkInterfaceInfos = getNetworkInterfaceInfos(); mDNSes = getActiveNetworkDnsResolvers(context); WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); mWifiEnabled = wifiManager.isWifiEnabled(); mWifiInfo = wifiManager.getConnectionInfo(); mDhcpInfo = wifiManager.getDhcpInfo(); }
From source file:com.syncedsynapse.kore2.ui.hosts.AddHostFragmentZeroconf.java
/** * Starts the service discovery, setting up the UI accordingly *///from w w w . ja v a2 s. c o m public void startSearching() { LogUtils.LOGD(TAG, "Starting service discovery..."); searchCancelled = false; final Handler handler = new Handler(); final Thread searchThread = new Thread(new Runnable() { @Override public void run() { WifiManager wifiManager = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE); WifiManager.MulticastLock multicastLock = null; try { // Get wifi ip address int wifiIpAddress = wifiManager.getConnectionInfo().getIpAddress(); InetAddress wifiInetAddress = NetUtils.intToInetAddress(wifiIpAddress); // Acquire multicast lock multicastLock = wifiManager.createMulticastLock("kore2.multicastlock"); multicastLock.setReferenceCounted(false); multicastLock.acquire(); JmDNS jmDns = (wifiInetAddress != null) ? JmDNS.create(wifiInetAddress) : JmDNS.create(); // Get the json rpc service list final ServiceInfo[] serviceInfos = jmDns.list(MDNS_XBMC_SERVICENAME, DISCOVERY_TIMEOUT); synchronized (lock) { // If the user didn't cancel the search, and we are sill in the activity if (!searchCancelled && isAdded()) { handler.post(new Runnable() { @Override public void run() { if ((serviceInfos == null) || (serviceInfos.length == 0)) { noHostFound(); } else { foundHosts(serviceInfos); } } }); } } } catch (IOException e) { LogUtils.LOGD(TAG, "Got an IO Exception", e); } finally { if (multicastLock != null) multicastLock.release(); } } }); titleTextView.setText(R.string.searching); messageTextView.setText(Html.fromHtml(getString(R.string.wizard_search_message))); messageTextView.setMovementMethod(LinkMovementMethod.getInstance()); progressBar.setVisibility(View.VISIBLE); hostListGridView.setVisibility(View.GONE); // Setup buttons nextButton.setVisibility(View.INVISIBLE); previousButton.setVisibility(View.VISIBLE); previousButton.setText(android.R.string.cancel); previousButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { synchronized (lock) { searchCancelled = true; noHostFound(); } } }); searchThread.start(); }
From source file:de.androidbytes.adbconnect.presentation.services.WirelessAdbManagingService.java
private boolean isTrustedNetwork() { WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE); String currentConntectedSSID = wifiManager.getConnectionInfo().getSSID().replaceAll("\"", ""); Set<String> trustedNetworks = PreferenceUtility.getTrustedNetworks(getApplicationContext()); boolean isTrustedNetwork; if (trustedNetworks != null && trustedNetworks.size() > 0) { isTrustedNetwork = trustedNetworks.contains(currentConntectedSSID); } else {//from ww w . jav a 2s . c om isTrustedNetwork = false; } return isTrustedNetwork; }
From source file:com.tvs.signaltracker.STService.java
private void UpdateWiFi() { SupplicantState supState;//www . j av a 2 s .com WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); supState = wifiInfo.getSupplicantState(); CommonHandler.WifiConnected = (supState == SupplicantState.COMPLETED); }
From source file:RhodesService.java
/** * This method is used only for non-Motorola devices as the UUID needs to be computed by other parameters. * @return 32-byte long UUID//from w w w . j a v a 2 s . com */ private static String computeUUID() { RhodesService srv = RhodesService.getInstance(); if (srv == null) throw new IllegalStateException("No rhodes service instance at this moment"); String res = ""; WifiManager wifi = (WifiManager) srv.getSystemService(Context.WIFI_SERVICE); // Get WiFi status WifiInfo wifiInfo = wifi.getConnectionInfo(); String macAddress = wifiInfo.getMacAddress(); macAddress = macAddress.replaceAll(":", ""); UUID localUuid = UUID.nameUUIDFromBytes(macAddress.getBytes()); res = localUuid.toString().replaceAll("-", ""); return res.toUpperCase(); }
From source file:by.zatta.pilight.connection.ConnectionService.java
private boolean addedToPreferences() { String currentNetwork = null; ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = cm.getActiveNetworkInfo(); if (!(info == null)) { // Log.d(TAG, "networkInfo: " + info.getExtraInfo()); currentNetwork = info.getExtraInfo(); }//from w ww .j av a2s . co m WifiManager wifiManager = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); if (!(wifiInfo == null)) { // Log.d(TAG, "wifiInfo:" + wifiInfo.getSSID()); currentNetwork = wifiInfo.getSSID(); } if (currentNetwork == null) return false; SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(aCtx); String previous = prefs.getString("networks_known", ""); // Log.d(TAG, previous); currentNetwork = currentNetwork.replace("\"", ""); if (previous.contains(currentNetwork)) { // Log.d(TAG, previous + " did contain " + currentNetwork); return false; } else { previous = previous + "|&|" + currentNetwork; // Log.d(TAG, previous); Editor edit = prefs.edit(); edit.putString("networks_known", previous); edit.commit(); return true; } }
From source file:de.qspool.clementineremote.ui.ConnectActivity.java
/** * We couldn't connect to clementine. Inform the user *///from www . j a v a 2s . co m void noConnection() { // Do not display dialog if the activity has finished! if (this.isFinishing()) { return; } // Check if we have not a local ip WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); int ip = wifiInfo.getIpAddress(); // Get the current wifi state if (!Utilities.onWifi()) { Utilities.ShowMessageDialog(this, R.string.connectdialog_error, R.string.wifi_disabled); } else if (!Utilities.ToInetAddress(ip).isSiteLocalAddress()) { Utilities.ShowMessageDialog(this, R.string.connectdialog_error, R.string.no_private_ip); } else { Utilities.ShowMessageDialog(this, getString(R.string.connectdialog_error), getString(R.string.check_ip, getString(R.string.clementine_version)), false); } }
From source file:com.example.gemswin.screancasttest.MainActivity_Reciever.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_reciever); WifiManager wm = (WifiManager) getSystemService(WIFI_SERVICE); String ip = Formatter.formatIpAddress(wm.getConnectionInfo().getIpAddress()); TextView text = (TextView) findViewById(R.id.textView); planetList = new ArrayList<String>(); mTextureView = (TextureView) findViewById(R.id.textureView); mTextureView.setSurfaceTextureListener(this); mTextureView.requestLayout();/* ww w.j a v a2 s . c o m*/ mTextureView.invalidate(); mTextureView.setOpaque(false); pref = new PrefManager(getApplicationContext()); text.setText(ip); mTask = new ReceiverAsyncTask(getApplicationContext(), this); mTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }
From source file:org.xbmc.kore.ui.hosts.AddHostFragmentZeroconf.java
/** * Starts the service discovery, setting up the UI accordingly *//* w w w.j a v a 2 s . c o m*/ public void startSearching() { if (!isNetworkConnected()) { noNetworkConnection(); return; } LogUtils.LOGD(TAG, "Starting service discovery..."); searchCancelled = false; final Handler handler = new Handler(); final Thread searchThread = new Thread(new Runnable() { @Override public void run() { WifiManager wifiManager = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE); WifiManager.MulticastLock multicastLock = null; try { // Get wifi ip address int wifiIpAddress = wifiManager.getConnectionInfo().getIpAddress(); InetAddress wifiInetAddress = NetUtils.intToInetAddress(wifiIpAddress); // Acquire multicast lock multicastLock = wifiManager.createMulticastLock("kore2.multicastlock"); multicastLock.setReferenceCounted(false); multicastLock.acquire(); JmDNS jmDns = (wifiInetAddress != null) ? JmDNS.create(wifiInetAddress) : JmDNS.create(); // Get the json rpc service list final ServiceInfo[] serviceInfos = jmDns.list(MDNS_XBMC_SERVICENAME, DISCOVERY_TIMEOUT); synchronized (lock) { // If the user didn't cancel the search, and we are sill in the activity if (!searchCancelled && isAdded()) { handler.post(new Runnable() { @Override public void run() { if ((serviceInfos == null) || (serviceInfos.length == 0)) { noHostFound(); } else { foundHosts(serviceInfos); } } }); } } } catch (IOException e) { LogUtils.LOGD(TAG, "Got an IO Exception", e); } finally { if (multicastLock != null) multicastLock.release(); } } }); titleTextView.setText(R.string.searching); messageTextView.setText(Html.fromHtml(getString(R.string.wizard_search_message))); messageTextView.setMovementMethod(LinkMovementMethod.getInstance()); progressBar.setVisibility(View.VISIBLE); hostListGridView.setVisibility(View.GONE); // Setup buttons nextButton.setVisibility(View.INVISIBLE); previousButton.setVisibility(View.VISIBLE); previousButton.setText(android.R.string.cancel); previousButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { synchronized (lock) { searchCancelled = true; noHostFound(); } } }); searchThread.start(); }