List of usage examples for android.net.wifi WifiManager getConnectionInfo
public WifiInfo getConnectionInfo()
From source file:com.heneryh.aquanotes.io.ApexExecutor.java
/** * Execute a {@link HttpGet} request, passing a valid response through * to the specified XML parser. This common method can then be used to parse * various kinds of XML feeds.//from ww w . j a va2 s .com */ public void executeGet(Uri ctrlUri, DefaultHandler xmlParser) throws HandlerException { controllerUri = ctrlUri; Cursor cursor = null; String username = null; String password = null; String apexBaseURL = null; String apexWANURL = null; String apexWiFiURL = null; String apexWiFiSID = null; String controllerType = null; /** * Poll the database for facts about this controller */ try { cursor = mDbResolver.query(controllerUri, ControllersQuery.PROJECTION, null, null, null); if (cursor != null && cursor.moveToFirst()) { username = cursor.getString(ControllersQuery.USER); password = cursor.getString(ControllersQuery.PW); apexWANURL = cursor.getString(ControllersQuery.WAN_URL); apexWiFiURL = cursor.getString(ControllersQuery.LAN_URL); apexWiFiSID = cursor.getString(ControllersQuery.WIFI_SSID); controllerType = cursor.getString(ControllersQuery.MODEL); } } catch (SQLException e) { throw new HandlerException("Database error getting controller data."); } finally { if (cursor != null) { cursor.close(); } } /** * Depending on whether or not we are on the 'Home' wifi network we want to use either the * WAN or LAN URL. * * Uhg, WifiManager stuff below crashes if wifi not enabled so first we have to check if * on wifi. */ ConnectivityManager cm = (ConnectivityManager) mActContext.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); if (netInfo.getType() == ConnectivityManager.TYPE_WIFI) { /** * Get the currently connected SSID, if it matches the 'Home' one then use the local WiFi URL rather than the public one */ WifiManager wm = (WifiManager) mActContext.getSystemService(Context.WIFI_SERVICE); WifiInfo wInfo = wm.getConnectionInfo(); // somewhere read this was a quoted string but appears not to be if (wInfo.getSSID().equalsIgnoreCase(apexWiFiSID)) { apexBaseURL = apexWiFiURL; } else { apexBaseURL = apexWANURL; } } else { apexBaseURL = apexWANURL; } /** * for this function we need to append to the URL. To be safe we try to catch various * forms of URL that might be entered by the user: * * check if the "/" was put on the end */ if (!apexBaseURL.endsWith("/")) { String tmp = apexBaseURL + "/"; apexBaseURL = tmp; } /** * check if it starts with an "http://" */ if (!apexBaseURL.toLowerCase().startsWith("http://")) { String tmp = "http://" + apexBaseURL; apexBaseURL = tmp; } // oh, we should also check if it ends with an "status.sht" on the end and remove it. /** * When all cleaned up, add the xml portion of the url to grab the status. * * TODO: we tried to make this call handle various xml feeds but this call is hardcoded * for the status feed. */ String apexURL = apexBaseURL + "cgi-bin/status.xml"; final HttpUriRequest request = new HttpGet(apexURL); executeWhySeparate(request, xmlParser, username, password); }
From source file:uk.bowdlerize.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. switch (item.getItemId()) { case R.id.action_add: { AlertDialog.Builder builder = new AlertDialog.Builder(this); // Get the layout inflater LayoutInflater inflater = getLayoutInflater(); View dialogView = inflater.inflate(R.layout.dialog_add_url, null); final EditText urlET = (EditText) dialogView.findViewById(R.id.urlET); builder.setView(dialogView)/*from ww w .java2s .c o m*/ .setPositiveButton(R.string.action_add, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { Bundle extras = new Bundle(); Intent receiveURLIntent = new Intent(MainActivity.this, CensorCensusService.class); extras.putString("url", urlET.getText().toString()); extras.putString("hash", MD5(urlET.getText().toString())); extras.putInt("urgency", 0); extras.putBoolean("local", true); //Add our extra info if (getSharedPreferences(MainActivity.class.getSimpleName(), Context.MODE_PRIVATE) .getBoolean("sendISPMeta", true)) { WifiManager wifiMgr = (WifiManager) getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiMgr.getConnectionInfo(); TelephonyManager telephonyManager = ((TelephonyManager) getSystemService( Context.TELEPHONY_SERVICE)); if (wifiMgr.isWifiEnabled() && null != wifiInfo.getSSID()) { LocalCache lc = null; Pair<Boolean, String> seenBefore = null; try { lc = new LocalCache(MainActivity.this); lc.open(); seenBefore = lc.findSSID(wifiInfo.getSSID().replaceAll("\"", "")); } catch (Exception e) { e.printStackTrace(); } if (null != lc) lc.close(); if (seenBefore.first) { extras.putString("isp", seenBefore.second); } else { extras.putString("isp", "unknown"); } try { extras.putString("sim", telephonyManager.getSimOperatorName()); } catch (Exception e) { e.printStackTrace(); } } else { try { extras.putString("isp", telephonyManager.getNetworkOperatorName()); } catch (Exception e) { e.printStackTrace(); } try { extras.putString("sim", telephonyManager.getSimOperatorName()); } catch (Exception e) { e.printStackTrace(); } } } receiveURLIntent.putExtras(extras); startService(receiveURLIntent); dialog.cancel(); } }).setNegativeButton(R.string.action_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); builder.show(); return true; } } return super.onOptionsItemSelected(item); }
From source file:com.heneryh.aquanotes.io.ApexExecutor.java
public void updateOutlet(Cursor cursor, String outletName, int position) throws HandlerException { /**/*from w w w . jav a 2s .c o m*/ * The cursor contains all of the controller details. */ String lanUri = cursor.getString(ControllersQuery.LAN_URL); String wanUri = cursor.getString(ControllersQuery.WAN_URL); String user = cursor.getString(ControllersQuery.USER); String pw = cursor.getString(ControllersQuery.PW); String ssid = cursor.getString(ControllersQuery.WIFI_SSID); String model = cursor.getString(ControllersQuery.MODEL); // Uhg, WifiManager stuff below crashes in AVD if wifi not enabled so first we have to check if on wifi ConnectivityManager cm = (ConnectivityManager) mActContext.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo nInfo = cm.getActiveNetworkInfo(); String apexBaseURL; if (nInfo.getType() == ConnectivityManager.TYPE_WIFI) { // Get the currently connected SSID, if it matches the 'Home' one then use the local WiFi URL rather than the public one WifiManager wm = (WifiManager) mActContext.getSystemService(Context.WIFI_SERVICE); WifiInfo wInfo = wm.getConnectionInfo(); // somewhere read this was a quoted string but appears not to be if (wInfo.getSSID().equalsIgnoreCase(ssid)) { // the ssid will be quoted in the info class apexBaseURL = lanUri; } else { apexBaseURL = wanUri; } } else { apexBaseURL = wanUri; } // for this function we need to append to the URL. I should really // check if the "/" was put on the end by the user here to avoid // possible errors. if (!apexBaseURL.endsWith("/")) { String tmp = apexBaseURL + "/"; apexBaseURL = tmp; } // oh, we should also check if it starts with an "http://" if (!apexBaseURL.toLowerCase().startsWith("http://")) { String tmp = "http://" + apexBaseURL; apexBaseURL = tmp; } // oh, we should also check if it ends with an "status.sht" on the end and remove it. // This used to be common for both the Apex and ACiii but during // the 4.04 beta Apex release it seemed to have broke and forced // me to use status.sht for the Apex. Maybe it was fixed but I // haven't checked it. // edit - this was not needed for the longest while but now that we are pushing just one // outlet, the different methods seem to be needed again. Really not sure why. String apexURL; if (model.equalsIgnoreCase("AC4")) { apexURL = apexBaseURL + "status.sht"; } else { apexURL = apexBaseURL + "cgi-bin/status.cgi"; } //Create credentials for basic auth // create a basic credentials provider and pass the credentials // Set credentials provider for our default http client so it will use those credentials UsernamePasswordCredentials c = new UsernamePasswordCredentials(user, pw); BasicCredentialsProvider cP = new BasicCredentialsProvider(); cP.setCredentials(AuthScope.ANY, c); ((DefaultHttpClient) mHttpClient).setCredentialsProvider(cP); // Build the POST update which looks like this: // form="status" // method="post" // action="status.sht" // // name="T5s_state", value="0" (0=Auto, 1=Man Off, 2=Man On) // submit -> name="Update", value="Update" // -- or // name="FeedSel", value="0" (0=A, 1=B) // submit -> name="FeedCycle", value="Feed" // -- or // submit -> name="FeedCycle", value="Feed Cancel" HttpPost httppost = new HttpPost(apexURL); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); // Add your data nameValuePairs.add(new BasicNameValuePair("name", "status")); nameValuePairs.add(new BasicNameValuePair("method", "post")); if (model.equalsIgnoreCase("AC4")) { nameValuePairs.add(new BasicNameValuePair("action", "status.sht")); } else { nameValuePairs.add(new BasicNameValuePair("action", "/cgi-bin/status.cgi")); } String pendingStateS = String.valueOf(position); nameValuePairs.add(new BasicNameValuePair(outletName + "_state", pendingStateS)); nameValuePairs.add(new BasicNameValuePair("Update", "Update")); try { httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse resp = mHttpClient.execute(httppost); final int status = resp.getStatusLine().getStatusCode(); if (status != HttpStatus.SC_OK) { throw new HandlerException( "Unexpected server response " + resp.getStatusLine() + " for " + httppost.getRequestLine()); } } catch (HandlerException e) { throw e; } catch (ClientProtocolException e) { throw new HandlerException("Problem reading remote response for " + httppost.getRequestLine(), e); } catch (IOException e) { throw new HandlerException("Problem reading remote response for " + httppost.getRequestLine(), e); } }
From source file:org.sufficientlysecure.keychain.ui.transfer.presenter.TransferPresenter.java
private String getConnectedWifiSsid() { WifiManager wifiManager = (WifiManager) context.getApplicationContext() .getSystemService(Context.WIFI_SERVICE); if (wifiManager == null) { return null; }//ww w . j a v a 2 s . co m WifiInfo info = wifiManager.getConnectionInfo(); if (info == null) { return null; } // getSSID will return the ssid in quotes if it is valid utf-8. we only return it in that case. String ssid = info.getSSID(); if (ssid.charAt(0) != '"') { return null; } return ssid.substring(1, ssid.length() - 1); }
From source file:com.heneryh.aquanotes.io.ApexExecutor.java
public void feedCycle(Cursor cursor, int cycleNumber) throws HandlerException { /**// www . j ava 2s. c o m * The cursor contains all of the controller details. */ String lanUri = cursor.getString(ControllersQuery.LAN_URL); String wanUri = cursor.getString(ControllersQuery.WAN_URL); String user = cursor.getString(ControllersQuery.USER); String pw = cursor.getString(ControllersQuery.PW); String ssid = cursor.getString(ControllersQuery.WIFI_SSID); String model = cursor.getString(ControllersQuery.MODEL); String apexBaseURL; // Determine if we are on the LAN or WAN and then use appropriate URL // Uhg, WifiManager stuff below crashes if wifi not enabled so first we have to check if on wifi ConnectivityManager cm = (ConnectivityManager) mActContext.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo nInfo = cm.getActiveNetworkInfo(); if (nInfo.getType() == ConnectivityManager.TYPE_WIFI) { // Get the currently connected SSID, if it matches the 'Home' one then use the local WiFi URL rather than the public one WifiManager wm = (WifiManager) mActContext.getSystemService(Context.WIFI_SERVICE); WifiInfo wInfo = wm.getConnectionInfo(); // somewhere read this was a quoted string but appears not to be if (wInfo.getSSID().equalsIgnoreCase(ssid)) { // the ssid will be quoted in the info class apexBaseURL = lanUri; } else { apexBaseURL = wanUri; } } else { apexBaseURL = wanUri; } // for this function we need to append to the URL. I should really // check if the "/" was put on the end by the user here to avoid // possible errors. if (!apexBaseURL.endsWith("/")) { String tmp = apexBaseURL + "/"; apexBaseURL = tmp; } // oh, we should also check if it starts with an "http://" if (!apexBaseURL.toLowerCase().startsWith("http://")) { String tmp = "http://" + apexBaseURL; apexBaseURL = tmp; } // we should also check if it ends with an "status.sht" on the end and remove it. // This used to be common for both the Apex and ACiii but during // the 4.04 beta Apex release it seemed to have broke and forced // me to use status.sht for the Apex. Maybe it was fixed but I // haven't checked it. // edit - this was not needed for the longest while but now that we are pushing just one // outlet, the different methods seem to be needed again. Really not sure why. String apexURL; if (model.equalsIgnoreCase("AC4")) { apexURL = apexBaseURL + "status.sht"; } else { apexURL = apexBaseURL + "cgi-bin/status.cgi"; } //Create credentials for basic auth // create a basic credentials provider and pass the credentials // Set credentials provider for our default http client so it will use those credentials UsernamePasswordCredentials c = new UsernamePasswordCredentials(user, pw); BasicCredentialsProvider cP = new BasicCredentialsProvider(); cP.setCredentials(AuthScope.ANY, c); ((DefaultHttpClient) mHttpClient).setCredentialsProvider(cP); // Build the POST update which looks like this: // form="status" // method="post" // action="status.sht" // // name="T5s_state", value="0" (0=Auto, 1=Man Off, 2=Man On) // submit -> name="Update", value="Update" // -- or // name="FeedSel", value="0" (0=A, 1=B) // submit -> name="FeedCycle", value="Feed" // -- or // submit -> name="FeedCycle", value="Feed Cancel" HttpPost httppost = new HttpPost(apexURL); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); // Add your data nameValuePairs.add(new BasicNameValuePair("name", "status")); nameValuePairs.add(new BasicNameValuePair("method", "post")); if (model.equalsIgnoreCase("AC4")) { nameValuePairs.add(new BasicNameValuePair("action", "status.sht")); } else { nameValuePairs.add(new BasicNameValuePair("action", "/cgi-bin/status.cgi")); } String cycleNumberString = Integer.toString(cycleNumber).trim(); if (cycleNumber < 4) { nameValuePairs.add(new BasicNameValuePair("FeedSel", cycleNumberString)); nameValuePairs.add(new BasicNameValuePair("FeedCycle", "Feed")); } else { nameValuePairs.add(new BasicNameValuePair("FeedCycle", "Feed Cancel")); } nameValuePairs.add(new BasicNameValuePair("Update", "Update")); try { httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse resp = mHttpClient.execute(httppost); final int status = resp.getStatusLine().getStatusCode(); if (status != HttpStatus.SC_OK) { throw new HandlerException( "Unexpected server response " + resp.getStatusLine() + " for " + httppost.getRequestLine()); } } catch (HandlerException e) { throw e; } catch (ClientProtocolException e) { throw new HandlerException("Problem reading remote response for " + httppost.getRequestLine(), e); } catch (IOException e) { throw new HandlerException("Problem reading remote response for " + httppost.getRequestLine(), e); } }
From source file:org.xbmc.kore.ui.sections.hosts.AddHostFragmentZeroconf.java
/** * Starts the service discovery, setting up the UI accordingly *///from w ww .j ava 2 s . co 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().getApplicationContext() .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:org.rm3l.ddwrt.tiles.status.wireless.WirelessClientsTile.java
@Nullable @Override//w w w . j av a 2 s.c om protected Loader<ClientDevices> getLoader(int id, Bundle args) { return new AsyncTaskLoader<ClientDevices>(this.mParentFragmentActivity) { @Nullable @Override public ClientDevices loadInBackground() { Log.d(LOG_TAG, "Init background loader for " + WirelessClientsTile.class + ": routerInfo=" + mRouter + " / this.mAutoRefreshToggle= " + mAutoRefreshToggle + " / nbRunsLoader=" + nbRunsLoader); //Determine broadcast address at each run (because that might change if connected to another network) try { final WifiManager wifiManager = (WifiManager) mParentFragmentActivity .getSystemService(Context.WIFI_SERVICE); mCurrentIpAddress = Utils.intToIp(wifiManager.getConnectionInfo().getIpAddress()); final InetAddress broadcastAddress = Utils.getBroadcastAddress(wifiManager); if (broadcastAddress != null) { mBroadcastAddress = broadcastAddress.getHostAddress(); } } catch (@NotNull final Exception e) { e.printStackTrace(); //No worries } if (nbRunsLoader > 0 && !mAutoRefreshToggle) { //Skip run Log.d(LOG_TAG, "Skip loader run"); return new ClientDevices().setException(new DDWRTTileAutoRefreshNotAllowedException()); } nbRunsLoader++; final ClientDevices devices = new ClientDevices(); if (DDWRTCompanionConstants.TEST_MODE) { //FIXME TEST MODE for (int i = 1, j = i + 1; i <= 15; i++, j++) { final int randomI = new Random().nextInt(i); final int randomJ = new Random().nextInt(j); devices.addDevice( new Device(String.format("A%1$s:B%1$s:C%1$s:D%2$s:E%2$s:F%2$s", randomI, randomJ)) .setIpAddress(String.format("172.17.1%1$s.2%2$s", randomI, randomJ)) .setSystemName(String.format("Device %1$s-%2$s", randomI, randomJ))); } Log.d(LOG_TAG, "wireless client devices: " + devices); return devices; //FIXME END TEST MODE } try { @Nullable final String[] output = SSHUtils.getManualProperty(mRouter, mGlobalPreferences, "grep dhcp-host /tmp/dnsmasq.conf | sed 's/.*=//' | awk -F , '{print \"" + MAP_KEYWORD + "\",$1,$3 ,$2}'", "awk '{print \"" + MAP_KEYWORD + "\",$2,$3,$4}' /tmp/dnsmasq.leases", "awk 'NR>1{print \"" + MAP_KEYWORD + "\",$4,$1,\"*\"}' /proc/net/arp", "echo done"); Log.d(LOG_TAG, "output: " + (output == null ? "NULL" : Arrays.toString(output))); if (output == null) { return null; } for (final String stdoutLine : output) { if ("done".equals(stdoutLine)) { break; } final List<String> as = Splitter.on(" ").splitToList(stdoutLine); if (as != null && as.size() >= 4 && MAP_KEYWORD.equals(as.get(0))) { final String macAddress = as.get(1); if ("00:00:00:00:00:00".equals(macAddress)) { //Skip clients with incomplete ARP set-up continue; } final Device device = new Device(macAddress); device.setIpAddress(as.get(2)); final String systemName = as.get(3); if (!"*".equals(systemName)) { device.setSystemName(systemName); } devices.addDevice(device); } } return devices; } catch (@NotNull final Exception e) { Log.e(LOG_TAG, e.getMessage() + ": " + Throwables.getStackTraceAsString(e)); return new ClientDevices().setException(e); } } }; }
From source file:system.info.reader.java
public String refresh() { //wifi/* w ww . j a v a2 s .c o m*/ WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); if ((wifiInfo != null) && (wifiInfo.getMacAddress() != null)) Properties.setInfo((String) propertyItems[4], wifiInfo.getMacAddress()); else Properties.setInfo((String) propertyItems[4], "not avaiable"); //String tmpsdcard = runCmd("df", ""); //if (tmpsdcard != null) result += tmpsdcard + "\n\n"; //setMap("dpi", dpi); //location LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE); List ll = lm.getProviders(true); Boolean foundLoc = false; for (int i = 0; i < ll.size(); i++) { Location lo = lm.getLastKnownLocation((String) ll.get(i)); if (lo != null) { Properties.setInfo((String) propertyItems[3], lo.getLatitude() + ":" + lo.getLongitude()); foundLoc = true; break; } } if (!foundLoc) Properties.setInfo((String) propertyItems[3], getString(R.string.locationHint)); ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); List serviceList = am.getRunningServices(10000); serviceInfo = ""; for (int i = 0; i < serviceList.size(); i++) { RunningServiceInfo rs = (RunningServiceInfo) serviceList.get(i); serviceInfo += rs.service.flattenToShortString() + "\n"; } //result += getString(R.string.nService) + serviceList.size() + "\n";//service number psInfo = ""; List appList = am.getRunningAppProcesses(); for (int i = 0; i < appList.size(); i++) { RunningAppProcessInfo as = (RunningAppProcessInfo) appList.get(i); psInfo += as.processName + "\n"; } //result += getString(R.string.nProcess) + appList.size() + "\n";//process number taskInfo = ""; List taskList = am.getRunningTasks(10000); for (int i = 0; i < taskList.size(); i++) { RunningTaskInfo ts = (RunningTaskInfo) taskList.get(i); taskInfo += ts.baseActivity.flattenToShortString() + "\n"; } //result += getString(R.string.nTask) + taskList.size() + "\n\n";//task number //result += getString(R.string.nProcess) + runCmd("ps", "") + "\n";//process number //setMap(getString(R.string.nApk), nApk); //send message to let view redraw. Message msg = mRedrawHandler.obtainMessage(); mRedrawHandler.sendMessage(msg); //properListItemAdapter.notifyDataSetChanged();//no use? Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(400); return ""; }
From source file:com.example.android.hawifi.MainActivity.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Override//from w w w .j ava 2 s .c o m protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Initialize text fragment that displays intro text. /*SimpleTextFragment introFragment = (SimpleTextFragment) getSupportFragmentManager().findFragmentById(R.id.intro_fragment); introFragment.setText(R.string.welcome_message); introFragment.getTextView().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16.0f);*/ // Initialize the logging framework. initializeLogging(); // Initialize the send buttons with a listener that for click events mTb = (ToggleButton) findViewById(R.id.tb_gl); mTb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { throwCmd("gln"); } else { throwCmd("glf"); } } }); mTb = (ToggleButton) findViewById(R.id.tb_dl); mTb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { throwCmd("dln"); } else { throwCmd("dlf"); } } }); mTb = (ToggleButton) findViewById(R.id.tb_gu); mTb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { throwCmd("gun"); } else { throwCmd("guf"); } } }); mTb = (ToggleButton) findViewById(R.id.tb_gd); mTb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { throwCmd("gdn"); } else { throwCmd("gdf"); } } }); mTb = (ToggleButton) findViewById(R.id.tb_du); mTb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { throwCmd("dun"); } else { throwCmd("duf"); } } }); mTb = (ToggleButton) findViewById(R.id.tb_dd); mTb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { throwCmd("ddn"); } else { throwCmd("ddf"); } } }); mTb = (ToggleButton) findViewById(R.id.tb_pc); mTb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { throwCmd("pcn"); } else { throwCmd("pcf"); } } }); mTb = (ToggleButton) findViewById(R.id.tb_tv); mTb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { throwCmd("tvn"); } else { throwCmd("tvf"); } } }); mTb = (ToggleButton) findViewById(R.id.tb_pl); mTb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { throwCmd("pln"); } else { throwCmd("plf"); } } }); mTb = (ToggleButton) findViewById(R.id.tb_pk); mTb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { throwCmd("pkn"); } else { throwCmd("pkf"); } } }); // piotr findViewById(R.id.radioButton0).setEnabled(false); findViewById(R.id.radioButton1).setEnabled(false); findViewById(R.id.radioButton2).setEnabled(false); findViewById(R.id.radioButton3).setEnabled(false); findViewById(R.id.radioButton4).setEnabled(false); myUrls = new ardUrl[5]; long nonce = myTime(); String result = ""; for (int i = 0; i < 5; i++) { myUrls[i] = new ardUrl(); myUrls[i].stat = false; } myUrls[0].url = "http://piotrlech.ddns.net:60000/"; myUrls[1].url = "http://piotrlech.ddns.net:58052/"; myUrls[2].url = "http://192.168.1.25:84/"; myUrls[3].url = "http://192.168.1.42:83/"; myUrls[4].url = "http://192.168.2.42:83/"; chkArduino asyncTask0, asyncTask1, asyncTask2, asyncTask3, asyncTask4; WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); String ap = wifiInfo.getSSID(); ap = ap.replace("\"", ""); if (ap.equals("FunBox-1EFF") || ap.equals("U4")) { //for (int i = 2; i < 4; i++) { // new chkArduino().execute(myUrls[i].url + "stm" + "/" + nonce + "/" + result); //} asyncTask2 = new chkArduino(); //asyncTask2.execute(myUrls[2].url + "stm" + "/" + nonce + "/" + result); asyncTask2.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, myUrls[2].url + "stm" + "/" + nonce + "/" + result); asyncTask3 = new chkArduino(); //asyncTask3.execute(myUrls[3].url + "stm" + "/" + nonce + "/" + result); asyncTask3.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, myUrls[3].url + "stm" + "/" + nonce + "/" + result); //StartAsyncTaskInParallel(asyncTask3); } if (ap.equals("PENTAGRAM")) { //for (int i = 4; i < 5; i++) { // new chkArduino().execute(myUrls[i].url + "stm" + "/" + nonce + "/" + result); //} asyncTask4 = new chkArduino(); asyncTask4.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, myUrls[4].url + "stm" + "/" + nonce + "/" + result); } //for (int i = 0; i < 2; i++) { // new chkArduino().execute(myUrls[i].url + "stm" + "/" + nonce + "/" + result); //} asyncTask0 = new chkArduino(); asyncTask0.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, myUrls[0].url + "stm" + "/" + nonce + "/" + result); asyncTask1 = new chkArduino(); asyncTask1.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, myUrls[1].url + "stm" + "/" + nonce + "/" + result); }
From source file:com.yozio.android.YozioHelper.java
private void setMacAddress() { try {//from ww w. j av a2s . c o m WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); if (wifiManager != null) { WifiInfo wifiInfo = wifiManager.getConnectionInfo(); if (wifiInfo != null) { macAddress = wifiInfo.getMacAddress(); } } } catch (Exception e) { } }