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.mozilla.SUTAgentAndroid.SUTAgentAndroid.java
/** Called when the activity is first created. */ @Override//ww w .j a v a 2 s .c om public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); fixScreenOrientation(); DoCommand dc = new DoCommand(getApplication()); Log.i("SUTAgentAndroid", dc.prgVersion); dc.FixDataLocalPermissions(); // Get configuration settings from "ini" file File dir = getFilesDir(); File iniFile = new File(dir, "SUTAgent.ini"); String sIniFile = iniFile.getAbsolutePath(); String lc = dc.GetIniData("General", "LogCommands", sIniFile); if (lc != "" && Integer.parseInt(lc) == 1) { SUTAgentAndroid.LogCommands = true; } SUTAgentAndroid.RegSvrIPAddr = dc.GetIniData("Registration Server", "IPAddr", sIniFile); SUTAgentAndroid.RegSvrIPPort = dc.GetIniData("Registration Server", "PORT", sIniFile); SUTAgentAndroid.HardwareID = dc.GetIniData("Registration Server", "HARDWARE", sIniFile); SUTAgentAndroid.Pool = dc.GetIniData("Registration Server", "POOL", sIniFile); SUTAgentAndroid.sTestRoot = dc.GetIniData("Device", "TestRoot", sIniFile); SUTAgentAndroid.Abi = android.os.Build.CPU_ABI; log(dc, "onCreate"); dc.SetTestRoot(SUTAgentAndroid.sTestRoot); Log.i("SUTAgentAndroid", "Test Root: " + SUTAgentAndroid.sTestRoot); tv = (TextView) this.findViewById(R.id.Textview01); if (getLocalIpAddress() == null) setUpNetwork(sIniFile); String macAddress = "Unknown"; if (android.os.Build.VERSION.SDK_INT > 8) { try { NetworkInterface iface = NetworkInterface .getByInetAddress(InetAddress.getAllByName(getLocalIpAddress())[0]); if (iface != null) { byte[] mac = iface.getHardwareAddress(); if (mac != null) { StringBuilder sb = new StringBuilder(); Formatter f = new Formatter(sb); for (int i = 0; i < mac.length; i++) { f.format("%02x%s", mac[i], (i < mac.length - 1) ? ":" : ""); } macAddress = sUniqueID = sb.toString(); } } } catch (UnknownHostException ex) { } catch (SocketException ex) { } } else { // Fall back to getting info from wifiman on older versions of Android, // which don't support the NetworkInterface interface WifiManager wifiMan = (WifiManager) getSystemService(Context.WIFI_SERVICE); if (wifiMan != null) { WifiInfo wifi = wifiMan.getConnectionInfo(); if (wifi != null) macAddress = wifi.getMacAddress(); if (macAddress != null) sUniqueID = macAddress; } } if (sUniqueID == null) { BluetoothAdapter ba = BluetoothAdapter.getDefaultAdapter(); if ((ba != null) && (ba.isEnabled() != true)) { ba.enable(); while (ba.getState() != BluetoothAdapter.STATE_ON) { try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } sUniqueID = ba.getAddress(); ba.disable(); while (ba.getState() != BluetoothAdapter.STATE_OFF) { try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } else { if (ba != null) { sUniqueID = ba.getAddress(); sUniqueID.toLowerCase(); } } } if (sUniqueID == null) { TelephonyManager mTelephonyMgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE); if (mTelephonyMgr != null) { sUniqueID = mTelephonyMgr.getDeviceId(); if (sUniqueID == null) { sUniqueID = "0011223344556677"; } } } String hwid = getHWID(this); sLocalIPAddr = getLocalIpAddress(); Toast.makeText(getApplication().getApplicationContext(), "SUTAgent [" + sLocalIPAddr + "] ...", Toast.LENGTH_LONG).show(); String sConfig = dc.prgVersion + lineSep; sConfig += "Test Root: " + sTestRoot + lineSep; sConfig += "Unique ID: " + sUniqueID + lineSep; sConfig += "HWID: " + hwid + lineSep; sConfig += "ABI: " + Abi + lineSep; sConfig += "OS Info" + lineSep; sConfig += "\t" + dc.GetOSInfo() + lineSep; sConfig += "Screen Info" + lineSep; int[] xy = dc.GetScreenXY(); sConfig += "\t Width: " + xy[0] + lineSep; sConfig += "\t Height: " + xy[1] + lineSep; sConfig += "Memory Info" + lineSep; sConfig += "\t" + dc.GetMemoryInfo() + lineSep; sConfig += "Network Info" + lineSep; sConfig += "\tMac Address: " + macAddress + lineSep; sConfig += "\tIP Address: " + sLocalIPAddr + lineSep; displayStatus(sConfig); sRegString = "NAME=" + sUniqueID; sRegString += "&IPADDR=" + sLocalIPAddr; sRegString += "&CMDPORT=" + 20701; sRegString += "&DATAPORT=" + 20700; sRegString += "&OS=Android-" + dc.GetOSInfo(); sRegString += "&SCRNWIDTH=" + xy[0]; sRegString += "&SCRNHEIGHT=" + xy[1]; sRegString += "&BPP=8"; sRegString += "&MEMORY=" + dc.GetMemoryConfig(); sRegString += "&HARDWARE=" + HardwareID; sRegString += "&POOL=" + Pool; sRegString += "&ABI=" + Abi; String sTemp = Uri.encode(sRegString, "=&"); sRegString = "register " + sTemp; pruneCommandLog(dc.GetSystemTime(), dc.GetTestRoot()); if (!bNetworkingStarted) { Thread thread = new Thread(null, doStartService, "StartServiceBkgnd"); thread.start(); bNetworkingStarted = true; Thread thread2 = new Thread(null, doRegisterDevice, "RegisterDeviceBkgnd"); thread2.start(); } monitorBatteryState(); // If we are returning from an update let'em know we're back Thread thread3 = new Thread(null, doUpdateCallback, "UpdateCallbackBkgnd"); thread3.start(); final Button goButton = (Button) findViewById(R.id.Button01); goButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { finish(); } }); }
From source file:com.laer.easycast.ImagePane.java
public void WiFiOptions() { DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { @Override//from w w w . j a v a 2s . c o m public void onClick(DialogInterface dialog, int which) { switch (which) { case DialogInterface.BUTTON_POSITIVE: // Yes button clicked WifiManager wifiManager = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE); wifiManager.setWifiEnabled(true); break; case DialogInterface.BUTTON_NEGATIVE: // No button clicked break; } } }; AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setMessage( "WiFi needs to be on for com.laer.easycast.streaming to a device. Would you like to turn it on?") .setPositiveButton("Yes", dialogClickListener).setNegativeButton("No", dialogClickListener).show(); }
From source file:com.carapp.login.splashActivity.java
private void getClientBranch() { MultipartEntity entity = new MultipartEntity(); try {/* www .ja va2s. co m*/ entity.addPart("action", new StringBody("init_config")); new AsyncWebServiceProcessingTask(context, entity, messagecheck, new AsynckCallback() { @Override public void run(String result) { if (UIUtils.checkJson(result, context)) { try { JSONObject jsonObject = new JSONObject(result); if (jsonObject.optString("satus").equals("success")) { PdfInfo.client = jsonObject.optString("client"); PdfInfo.branch = jsonObject.optString("branch"); Util.showCustomDialogWithoutButton(context, "Message", messagechecksucces, new Callback2() { @Override public void ok(final Dialog dialog) { final Handler handler = new Handler(); final Runnable runnable = new Runnable() { @Override public void run() { dialog.dismiss(); new AsyncWebServiceProcessingTask(context, null, "Please wait while checking date", new AsynckCallback() { @Override public void run(String result) { Log.e("date", "" + result); String sysdate = android.text.format.DateFormat .format("dd/MM/yyyy", new java.util.Date()) .toString(); if (result.equals(sysdate)) { Toast.makeText(context, "date match", Toast.LENGTH_SHORT).show(); new AsyncWebServiceProcessingTask( context, null, messagecheckday, new AsynckCallback() { @Override public void run( String result) { int day = Integer .parseInt( result); Calendar calendar = Calendar .getInstance(); int Today = calendar .get(Calendar.DAY_OF_WEEK); day++; if (day == Today) { Toast.makeText( context, "day is correct", Toast.LENGTH_SHORT) .show(); String ma_a = null; try { WifiManager wiman = (WifiManager) getSystemService( Context.WIFI_SERVICE); ma_a = wiman .getConnectionInfo() .getMacAddress(); Log.i(t, "" + ma_a); } catch (Exception e1) { e1.printStackTrace(); Log.i(t, " " + e1); } MultipartEntity entity = new MultipartEntity(); try { entity.addPart( "action", new StringBody( "device_authentication")); entity.addPart( "mac_address", new StringBody( ma_a)); new AsyncWebServiceProcessingTask( context, entity, "Checking License", new AsynckCallback() { @Override public void run( String result) { if (UIUtils .checkJson( result, context)) { try { JSONObject jsonObject = new JSONObject( result); if (jsonObject .optString( "satus") .equals("success")) { Toast.makeText( context, "LicenseCheck sucesses", Toast.LENGTH_SHORT) .show(); startActivity( new Intent( context, LoginActivity.class)); finish(); } else if (jsonObject .optString( "satus") .equals("error")) { Util.showCustomDialog( context, "Error", jsonObject .optString( "msg")); } } catch (Exception e) { e.printStackTrace(); } } } }).execute( PdfInfo.newjobcard); } catch (Exception e) { e.printStackTrace(); } } else { Util.showCustomDialogWithoutButton( context, "Error", messagecheckdayerror + " server day is " + day + " but your device is" + Today, new Callback2() { @Override public void ok( final Dialog dialog) { final Handler handler = new Handler(); final Runnable runnable = new Runnable() { @Override public void run() { dialog.dismiss(); finish(); } }; handler.postDelayed( runnable, 5000); } }); } } }).execute(PdfInfo.dayaddress); } else { Util.showCustomDialogWithoutButton( context, "Error", messagecheckdateerror + " server date is " + result + " but device date is " + sysdate, new Callback2() { @Override public void ok( final Dialog dialog) { new Timer().schedule( new TimerTask() { @Override public void run() { dialog.dismiss(); finish(); } }, 5000); } }); } } }).execute(PdfInfo.dateaddress); } }; handler.postDelayed(runnable, 5000); } }); } else if (jsonObject.optString("satus").equals("error")) { Util.showCustomDialogWithoutButton(context, "Message", messagechecksucces, new Callback2() { @Override public void ok(final Dialog dialog) { new Timer().schedule(new TimerTask() { @Override public void run() { dialog.dismiss(); finish(); } }, 5000); } }); } } catch (Exception e) { e.printStackTrace(); } } } }).execute(PdfInfo.newjobcard); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.terminal.ide.TermService.java
@Override public void onCreate() { compat = new ServiceForegroundCompat(this); mTermSessions = new ArrayList<TermSession>(); /**//from ww w. ja v a 2 s . c o m * ?? * @author wanghao * @date 2015-3-27 * ???Activity */ //?intent //warning??start.class //?mainActivity Intent openMainActivityIntent = new Intent(this, mainAvtivity.class); Intent openTerminalActivityIntent = new Intent(this, Term.class); openTerminalActivityIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); openMainActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Intent exitTerminalIntent = new Intent(this, ExitService.class); Notification sessionBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_launcher) .setContentTitle(getText(R.string.application_terminal)) .setContentText(getText(R.string.service_notify_text)) .setContentIntent(PendingIntent.getActivity(this, 0, openMainActivityIntent, 0)) .setStyle(new NotificationCompat.BigTextStyle().bigText(getText(R.string.service_notify_text))) .addAction(R.drawable.ic_action_iconfont_terminal, getText(R.string.notification_open_termianl), PendingIntent.getActivity(this, 0, openTerminalActivityIntent, Intent.FLAG_ACTIVITY_CLEAR_TOP)) .addAction(R.drawable.ic_action_iconfont_exit, getText(R.string.notification_exit_app), PendingIntent.getService(this, 0, exitTerminalIntent, 0)) .setOngoing(true).build(); compat.startForeground(RUNNING_NOTIFICATION, sessionBuilder); mPrefs = PreferenceManager.getDefaultSharedPreferences(this); mPrefs.registerOnSharedPreferenceChangeListener(this); mHardKeys.setKeyMappings(mPrefs); //Setup the Hard Key Mappings.. mSettings = new TermSettings(mPrefs); //Need to set the HOME Folder and Bash startup.. //Sometime getfilesdir return NULL ? mSessionInit = false; File home = getFilesDir(); if (home != null) { initSessions(home); } //Start a webserver for comms.. // mServer = new webserver(this); // mServer.start(); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE); //Get a wake lock mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TermDebug.LOG_TAG); mScreenLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, TermDebug.LOG_TAG); mWifiLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL, TermDebug.LOG_TAG); //Get the Initial Values // boolean cpulock = getStringPref("cpulock","1") == 1 ? true : false; // boolean wifilock = getStringPref("wifilock","0") == 1 ? true : false; // boolean screenlock = getStringPref("screenlock","0") == 1 ? true : false; setupWakeLocks(); Log.d(TermDebug.LOG_TAG, "TermService started"); return; }
From source file:com.francetelecom.rd.app.nodessimulator.NodeListActivity.java
private void setupMulticast() { WifiManager wifiManager = (WifiManager) getSystemService(android.content.Context.WIFI_SERVICE); multicastLock = wifiManager.createMulticastLock("com.francetelecom.rd"); multicastLock.setReferenceCounted(true); multicastLock.acquire();/* w ww . ja v a 2s .c om*/ }
From source file:org.basdroid.common.NetworkUtils.java
public static String getMacAddress(Context context) { WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); return wm.getConnectionInfo().getMacAddress(); }
From source file:com.xconns.peerdevicenet.core.CoreAPI.java
@TargetApi(5) @Override// w ww . j av a 2 s . c o m public void onCreate() { // TODO Auto-generated method stub super.onCreate(); Log.d(TAG, "RouterService onCreate()"); timer = new ScheduledThreadPoolExecutor(1); linkMgr = new TransportManager(this, linkHandler); linkMgr.onResume(); mMyDeviceInfo = new DeviceInfo(); //loc wifi myWifiLock = ((WifiManager) getSystemService(Context.WIFI_SERVICE)) .createWifiLock(WifiManager.WIFI_MODE_FULL, "mywifilock"); myWifiLock.acquire(); // init tcp connector mTCPConn = new TCPConnector(this); // notify others router is up by send ACTION_ROUTER_UP // eg. start remote intent service here Intent startupSignal = new Intent(Router.Intent.ACTION_ROUTER_UP); startService(startupSignal); // add notification and start service at foreground /*Notification notification = new Notification(R.drawable.router_icon, getText(R.string.router_notif_ticker), System.currentTimeMillis());*/ // Instantiate a Builder object. NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentTitle(getText(R.string.router_notif_title)) .setTicker(getText(R.string.router_notif_ticker)) .setContentText(getText(R.string.router_notif_message)).setSmallIcon(R.drawable.router_icon); // Intent notificationIntent = new Intent(Router.Intent.ACTION_CONNECTOR); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); builder.setContentIntent(pendingIntent); // using id of ticker text as notif id startForeground(R.string.router_notif_ticker, builder.build()); }
From source file:com.prey.PreyPhone.java
private void updateListWifi() { listWifi = new ArrayList<PreyPhone.Wifi>(); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || (ActivityCompat.checkSelfPermission(ctx, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(ctx, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED)) { WifiManager wifiMgr = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE); List<ScanResult> listScanResults = wifiMgr.getScanResults(); for (int i = 0; listScanResults != null && i < listScanResults.size(); i++) { ScanResult scan = listScanResults.get(i); Wifi _wifi = new Wifi(); _wifi.setSsid(scan.SSID);//from ww w . j a v a 2 s. co m _wifi.setMacAddress(scan.BSSID); _wifi.setSecurity(scan.capabilities); _wifi.setSignalStrength(String.valueOf(scan.level)); _wifi.setChannel(String.valueOf(getChannelFromFrequency(scan.frequency))); listWifi.add(_wifi); } } }
From source file:com.amazon.rvspeedtest.GcmIntentService.java
private String testDownloadSpeed() { String downloadSpeed = null;//from w w w . j a v a 2s .com // String url = "http://upload.wikimedia.org/wikipedia/commons/2/2d/Snake_River_%285mb%29.jpg"; // byte[] buf = new byte[1024]; // int n = 0; // long BeforeTime = System.nanoTime(); // long TotalRxBeforeTest = TrafficStats.getTotalRxBytes(); // Log.i(TAG, "Before test bytes :" + TotalRxBeforeTest); // // long TotalTxBeforeTest = TrafficStats.getTotalRxBytes(); // try { // InputStream is = new URL(url).openStream(); // int bytesRead; // while ((bytesRead = is.read(buf)) != -1) { // n++; // } // Log.i(TAG, "Value of n " + n); // long TotalRxAfterTest = TrafficStats.getTotalRxBytes(); // Log.i(TAG, "After test bytes :" + TotalRxAfterTest); // // long TotalTxAfterTest = TrafficStats.getTotalRxBytes(); // long AfterTime = System.nanoTime(); // // double TimeDifference = AfterTime - BeforeTime; // Log.i(TAG, "Time difference " + TimeDifference); // // double rxDiff = TotalRxAfterTest - TotalRxBeforeTest; // //Convert into kb // rxDiff /= 1024; //// double txDiff = TotalTxAfterTest - TotalTxBeforeTest; // // if ((rxDiff != 0)) { // double rxBPS = (rxDiff / (TimeDifference)) * Math.pow(10, 9); // total rx bytes per second. // downloadSpeed = Double.toString(rxBPS); //// double txBPS = (txDiff / (TimeDifference/1000)); // total tx bytes per second. // Log.i(TAG, String.valueOf(rxBPS) + "KBps. Total rx = " + rxDiff); //// testing[1] = String.valueOf(txBPS) + "bps. Total tx = " + txDiff; // } else { // Log.e(TAG, "Download speed is 0"); // } // } catch (Exception e) { // e.printStackTrace(); // } WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); if (wifiInfo != null) { Integer linkSpeed = wifiInfo.getLinkSpeed(); //measured using WifiInfo.LINK_SPEED_UNITS downloadSpeed = Integer.toString(linkSpeed); Log.i(TAG, "link speed : " + linkSpeed); } return downloadSpeed; }
From source file:com.qa.perf.emmageeplus.service.EmmageeService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { Log.i(LOG_TAG, "service onStart"); PendingIntent contentIntent = PendingIntent.getActivity(getBaseContext(), 0, new Intent(this, MainPageActivity.class), 0); NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentIntent(contentIntent).setSmallIcon(R.mipmap.icon).setWhen(System.currentTimeMillis()) .setAutoCancel(true).setContentTitle("Emmagee"); startForeground(startId, builder.build()); pid = intent.getExtras().getInt("pid"); uid = intent.getExtras().getInt("uid"); appName = intent.getExtras().getString("appName"); packageName = intent.getExtras().getString("packageName"); startActivity = intent.getExtras().getString("startActivity"); cpuInfo = new CpuInfo(getBaseContext(), pid, Integer.toString(uid)); readSettingInfo();//from ww w. j a v a 2 s . co m if (isFloating) { viFloatingWindow = LayoutInflater.from(this).inflate(R.layout.floating, null); txtUnusedMem = (TextView) viFloatingWindow.findViewById(R.id.memunused); txtTotalMem = (TextView) viFloatingWindow.findViewById(R.id.memtotal); txtTraffic = (TextView) viFloatingWindow.findViewById(R.id.traffic); btnWifi = (Button) viFloatingWindow.findViewById(R.id.wifi); wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); if (wifiManager.isWifiEnabled()) { btnWifi.setText(R.string.close_wifi); } else { btnWifi.setText(R.string.open_wifi); } txtUnusedMem.setText(getString(R.string.calculating)); txtUnusedMem.setTextColor(android.graphics.Color.RED); txtTotalMem.setTextColor(android.graphics.Color.RED); txtTraffic.setTextColor(android.graphics.Color.RED); Button btnStop = (Button) viFloatingWindow.findViewById(R.id.stop); btnStop.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(); intent.putExtra("isServiceStop", true); intent.setAction(SERVICE_ACTION); sendBroadcast(intent); stopSelf(); } }); createFloatingWindow(); } createResultCsv(); handler.postDelayed(task, 1000); return START_NOT_STICKY; }