List of usage examples for android.net.wifi WifiManager isWifiEnabled
public boolean isWifiEnabled()
From source file:com.laer.easycast.ImagePane.java
public void photoRaw(Bitmap image, String transition) { Log.i("photoraw", "photoraw called"); headers.put("X-Apple-Transition", transition); image.compress(Bitmap.CompressFormat.JPEG, 100, wr); MainActivity obj = (MainActivity) getActivity(); WifiManager wifi = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE); if (obj.URL != null) { new PhotoAirplay().execute(); } else if (obj.URL == null && !wifi.isWifiEnabled()) { WiFiOptions();/* w ww. j ava 2s. c om*/ if (obj.URL == null) { Toast.makeText(getActivity(), "No compatible devices found", Toast.LENGTH_SHORT).show(); } } }
From source file:cordova.plugins.Diagnostic.java
public void setWifiState(boolean enable) { WifiManager wifiManager = (WifiManager) this.cordova.getActivity().getSystemService(Context.WIFI_SERVICE); if (enable && !wifiManager.isWifiEnabled()) { wifiManager.setWifiEnabled(true); } else if (!enable && wifiManager.isWifiEnabled()) { wifiManager.setWifiEnabled(false); }//w w w . j av a 2 s . co m }
From source file:com.trigger_context.Main_Service.java
private boolean testConditions(String mac) { SharedPreferences conditions = getSharedPreferences(mac, MODE_PRIVATE); Map<String, ?> cond_map = conditions.getAll(); Set<String> key_set = cond_map.keySet(); boolean takeAction = true; if (key_set.contains("bluetooth")) { // checking the current state against the state set by the user final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); takeAction = new Boolean(bluetoothAdapter.isEnabled()) .equals(conditions.getString("bluetooth", "false")); }// w ww . j a v a2s .c o m if (takeAction && key_set.contains("wifi")) { final WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE); takeAction = new Boolean(wm.isWifiEnabled()) == conditions.getBoolean("wifi", false); } if (takeAction && key_set.contains("gps")) { final LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); takeAction = new Boolean(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) .equals(conditions.getString("gps", "false")); } if (takeAction && key_set.contains("sms")) { final Uri SMS_INBOX = Uri.parse("content://sms/inbox"); Cursor c = getContentResolver().query(SMS_INBOX, null, "read = 0", null, null); if (c != null) { int unreadMessagesCount = c.getCount(); c.close(); takeAction = new Boolean(unreadMessagesCount > 0).equals(conditions.getString("sms", "false")); } else { takeAction = false; } } // "NOT TESTED" head set, missed call, accelerometer, proximity, gyro, // orientation if (takeAction && key_set.contains("headset")) { AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE); takeAction = am.isMusicActive() == conditions.getBoolean("headset", false); // am.isWiredHeadsetOn() is deprecated } /* * if(takeAction && key_set.contains("missedCall")) { final String[] * projection = null; final String selection = null; final String[] * selectionArgs = null; final String sortOrder = * android.provider.CallLog.Calls.DATE + " DESC"; Cursor cursor = null; * try{ cursor = getApplicationContext().getContentResolver().query( * Uri.parse("content://call_log/calls"), projection, selection, * selectionArgs, sortOrder); while (cursor.moveToNext()) { String * callLogID = * cursor.getString(cursor.getColumnIndex(android.provider.CallLog * .Calls._ID)); String callNumber = * cursor.getString(cursor.getColumnIndex * (android.provider.CallLog.Calls.NUMBER)); String callDate = * cursor.getString * (cursor.getColumnIndex(android.provider.CallLog.Calls.DATE)); String * callType = * cursor.getString(cursor.getColumnIndex(android.provider.CallLog * .Calls.TYPE)); String isCallNew = * cursor.getString(cursor.getColumnIndex * (android.provider.CallLog.Calls.NEW)); if(Integer.parseInt(callType) * == android.provider.CallLog.Calls.MISSED_CALL_TYPE && * Integer.parseInt(isCallNew) > 0){ * * } } }catch(Exception ex){ }finally{ cursor.close(); } * * } */ return takeAction; }
From source file:org.noise_planet.noisecapture.MainActivity.java
private boolean checkWifiState() { // Check connection state WifiManager wifiMgr = (WifiManager) getSystemService(Context.WIFI_SERVICE); if (wifiMgr.isWifiEnabled()) { // WiFi adapter is ON WifiInfo wifiInfo = wifiMgr.getConnectionInfo(); if (wifiInfo.getNetworkId() == -1) { return false; // Not connected to an access-Point }/*from ww w. j a va2 s .co m*/ // Connected to an Access Point return true; } else { return false; // WiFi adapter is OFF } }
From source file:com.jesjimher.bicipalma.MesProperesActivity.java
/** Called when the activity is first created. */ @Override/*from w w w. j a v a2 s . c om*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.mesproperes); this.prefs = PreferenceManager.getDefaultSharedPreferences(this); // Si s'ha d'activar el wifi en inici, fer-ho WifiManager wm = (WifiManager) this.getSystemService(Context.WIFI_SERVICE); // Guardar el estado actual para restaurarlo al salir this.estatWifi = wm.isWifiEnabled(); if (prefs.getBoolean("activarWifiPref", false)) wm.setWifiEnabled(true); // Cargamos la versin cacheada de las estaciones leerCacheEstaciones(); actualizarListado(); // Iniciamos la descarga de las estaciones y su estado desde la web (en un thread aparte) descargaEstaciones = new RecuperarEstacionesTask(this); descargaEstaciones.execute(); // Inicialmente se busca por red (ms rpido) // dBuscaUbic=ProgressDialog.show(c, "",getString(R.string.buscandoubica),true,true); // Toast.makeText(getApplicationContext(), "Activando", Toast.LENGTH_SHORT).show(); locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_COARSE); providerCoarse = locationManager.getBestProvider(criteria, true); if (providerCoarse == null) { Toast.makeText(getApplicationContext(), "No hay forma de posicionarse", Toast.LENGTH_SHORT).show(); return; } locationManager.requestLocationUpdates(providerCoarse, 10, 0, (LocationListener) this); // Usar ltima ubicacin conocida de red para empezar y recibir futuras actualizaciones lBest = locationManager.getLastKnownLocation(providerCoarse); // Guardar el inicio de bsqueda de ubicacin para no pasarse de tiempo //tIni=new Date().getTime(); tIni = System.currentTimeMillis(); // Crear listeners para mostrar estacin en mapa, o abrir men con clic largo ListView lv = (ListView) findViewById(R.id.listado); lv.setOnItemClickListener((OnItemClickListener) this); lv.setOnItemLongClickListener((OnItemLongClickListener) this); }
From source file:com.sentaroh.android.SMBSync2.CommonUtilities.java
public boolean isWifiActive() { boolean ret = false; WifiManager mWifi = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); if (mWifi.isWifiEnabled()) ret = true;/*from w ww . jav a 2s . c o m*/ addDebugMsg(2, "I", "isWifiActive WifiEnabled=" + ret); return ret; }
From source file:cn.apputest.ctria.section2.Lucha2Activity.java
public String getLocalIPAddress() { // ?wifi?/*from w w w . j ava2 s . co 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:com.ntsync.android.sync.syncadapter.SyncAdapter.java
@Override public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {/*from www .j av a 2 s. c o m*/ PaymentVerificationService.startVerificationTimer(mContext.getApplicationContext()); SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(mContext); boolean onlyWifi = settings.getBoolean("sync_onlywifi", false); if (onlyWifi) { WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); if (!wifiManager.isWifiEnabled()) { Log.i(TAG, "Cancel Sync, because Wifi is not enabled."); syncResult.stats.numIoExceptions++; return; } } AccountSyncResult ourSyncResult = new AccountSyncResult(account.name); try { SyncUtils.stopProcessDataChanges(); performSync(account, extras, syncResult, ourSyncResult); updateClientMod(account); } catch (InterruptedException e1) { LogHelper.logWCause(TAG, "Failed to sync.", e1); syncResult.databaseError = true; } finally { SyncUtils.startProcessDataChanges(); ourSyncResult.setLastSyncTime(new Date()); SyncUtils.setSyncResult(mAccountManager, account, ourSyncResult); } }
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 w w w .j av a 2 s . c o m*/ // Log.v("","ssid="+ssid); } addDebugMsg(2, "I", "getConnectedWifiSsid WifiEnabled=" + mWifi.isWifiEnabled() + ", SSID=" + ssid + ", result=" + ret); return ret; }
From source file:com.landenlabs.all_devtool.ConsoleFragment.java
@SuppressLint("DefaultLocale") private void updateConsole() { if (mSystemViews.isEmpty()) return;/*from ww w . j a va 2s. co m*/ try { // ----- System ----- int threadCount = Thread.activeCount(); ApplicationInfo appInfo = getActivity().getApplicationInfo(); mSystemViews.get(SYSTEM_PACKAGE).get(1).setText(appInfo.packageName); mSystemViews.get(SYSTEM_MODEL).get(1).setText(Build.MODEL); mSystemViews.get(SYSTEM_ANDROID).get(1).setText(Build.VERSION.RELEASE); if (Build.VERSION.SDK_INT >= 16) { int lines = 0; final StringBuilder permSb = new StringBuilder(); try { PackageInfo pi = getContext().getPackageManager().getPackageInfo(getContext().getPackageName(), PackageManager.GET_PERMISSIONS); for (int i = 0; i < pi.requestedPermissions.length; i++) { if ((pi.requestedPermissionsFlags[i] & PackageInfo.REQUESTED_PERMISSION_GRANTED) != 0) { permSb.append(pi.requestedPermissions[i]).append("\n"); lines++; } } } catch (Exception e) { } final int lineCnt = lines; mSystemViews.get(SYSTEM_PERM).get(1).setText(String.format("%d perms [press]", lines)); mSystemViews.get(SYSTEM_PERM).get(1).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (v.getTag() == null) { String permStr = permSb.toString().replaceAll("android.permission.", "") .replaceAll("\n[^\n]*permission", ""); mSystemViews.get(SYSTEM_PERM).get(1).setText(permStr); mSystemViews.get(SYSTEM_PERM).get(0).setLines(lineCnt); mSystemViews.get(SYSTEM_PERM).get(1).setLines(lineCnt); mSystemViews.get(SYSTEM_PERM).get(1).setTag(lineCnt); } else { mSystemViews.get(SYSTEM_PERM).get(1).setText(String.format("%d perms", lineCnt)); mSystemViews.get(SYSTEM_PERM).get(0).setLines(1); mSystemViews.get(SYSTEM_PERM).get(1).setLines(1); mSystemViews.get(SYSTEM_PERM).get(1).setTag(null); } } }); } else { String permStr = ""; if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) permStr += (" Find Loc"); if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) permStr += (" Coarse Loc"); mSystemViews.get(SYSTEM_PERM).get(1).setText(permStr); } ActivityManager actMgr = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE); int processCnt = actMgr.getRunningAppProcesses().size(); mSystemViews.get(SYSTEM_PROCESSES).get(1).setText(String.format("%d", consoleState.processCnt)); mSystemViews.get(SYSTEM_PROCESSES).get(2).setText(String.format("%d", processCnt)); // mSystemViews.get(SYSTEM_BATTERY).get(1).setText(String.format("%d%%", consoleState.batteryLevel)); mSystemViews.get(SYSTEM_BATTERY).get(2) .setText(String.format("%%%d", calculateBatteryLevel(getActivity()))); // long cpuNano = Debug.threadCpuTimeNanos(); // mSystemViews.get(SYSTEM_CPU).get(2).setText(String.format("%d%%", cpuNano)); } catch (Exception ex) { m_log.e(ex.getMessage()); } try { // ----- Network WiFi----- WifiManager wifiMgr = (WifiManager) getContext().getApplicationContext() .getSystemService(Context.WIFI_SERVICE); if (wifiMgr != null && wifiMgr.isWifiEnabled() && wifiMgr.getDhcpInfo() != null) { DhcpInfo dhcpInfo = wifiMgr.getDhcpInfo(); mNetworkViews.get(NETWORK_WIFI_IP).get(1).setText(Formatter.formatIpAddress(dhcpInfo.ipAddress)); WifiInfo wifiInfo = wifiMgr.getConnectionInfo(); mNetworkViews.get(NETWORK_WIFI_SPEED).get(1).setText(String.valueOf(wifiInfo.getLinkSpeed())); int numberOfLevels = 10; int level = WifiManager.calculateSignalLevel(wifiInfo.getRssi(), numberOfLevels + 1); mNetworkViews.get(NETWORK_WIFI_SIGNAL).get(1) .setText(String.format("%%%d", 100 * level / numberOfLevels)); } } catch (Exception ex) { m_log.e(ex.getMessage()); } try { // ----- Network Traffic----- // int uid = android.os.Process.myUid(); mNetworkViews.get(NETWORK_RCV_BYTES).get(1).setText(String.format("%d", consoleState.netRxBytes)); mNetworkViews.get(NETWORK_RCV_PACK).get(1).setText(String.format("%d", consoleState.netRxPacks)); mNetworkViews.get(NETWORK_SND_BYTES).get(1).setText(String.format("%d", consoleState.netTxBytes)); mNetworkViews.get(NETWORK_SND_PACK).get(1).setText(String.format("%d", consoleState.netTxPacks)); mNetworkViews.get(NETWORK_RCV_BYTES).get(2) .setText(String.format("%d", TrafficStats.getTotalRxBytes())); mNetworkViews.get(NETWORK_RCV_PACK).get(2) .setText(String.format("%d", TrafficStats.getTotalRxPackets())); mNetworkViews.get(NETWORK_SND_BYTES).get(2) .setText(String.format("%d", TrafficStats.getTotalTxBytes())); mNetworkViews.get(NETWORK_SND_PACK).get(2) .setText(String.format("%d", TrafficStats.getTotalRxPackets())); mNetworkViews.get(NETWORK_RCV_BYTES).get(3) .setText(String.format("%d", TrafficStats.getTotalRxBytes() - consoleState.netRxBytes)); mNetworkViews.get(NETWORK_RCV_PACK).get(3) .setText(String.format("%d", TrafficStats.getTotalRxPackets() - consoleState.netRxPacks)); mNetworkViews.get(NETWORK_SND_BYTES).get(3) .setText(String.format("%d", TrafficStats.getTotalTxBytes() - consoleState.netTxBytes)); mNetworkViews.get(NETWORK_SND_PACK).get(3) .setText(String.format("%d", TrafficStats.getTotalRxPackets() - consoleState.netTxPacks)); } catch (Exception ex) { m_log.e(ex.getMessage()); } // ----- Memory ----- try { MemoryInfo mi = new MemoryInfo(); ActivityManager activityManager = (ActivityManager) getActivity() .getSystemService(Context.ACTIVITY_SERVICE); activityManager.getMemoryInfo(mi); long heapUsing = Debug.getNativeHeapSize(); Date now = new Date(); long deltaMsec = now.getTime() - consoleState.lastFreeze.getTime(); List<TextView> timeViews = mMemoryViews.get(MEMORY_TIME); timeViews.get(1).setText(TIMEFORMAT.format(consoleState.lastFreeze)); timeViews.get(2).setText(TIMEFORMAT.format(now)); timeViews.get(3).setText( DateUtils.getRelativeTimeSpanString(consoleState.lastFreeze.getTime(), now.getTime(), 0)); // timeViews.get(3).setText( String.valueOf(deltaMsec)); List<TextView> usingViews = mMemoryViews.get(MEMORY_USING); usingViews.get(1).setText(String.format("%d", consoleState.usingMemory)); usingViews.get(2).setText(String.format("%d", heapUsing)); usingViews.get(3).setText(String.format("%d", heapUsing - consoleState.usingMemory)); List<TextView> freeViews = mMemoryViews.get(MEMORY_FREE); freeViews.get(1).setText(String.format("%d", consoleState.freeMemory)); freeViews.get(2).setText(String.format("%d", mi.availMem)); freeViews.get(3).setText(String.format("%d", mi.availMem - consoleState.freeMemory)); List<TextView> totalViews = mMemoryViews.get(MEMORY_TOTAL); if (Build.VERSION.SDK_INT >= 16) { totalViews.get(1).setText(String.format("%d", consoleState.totalMemory)); totalViews.get(2).setText(String.format("%d", mi.totalMem)); totalViews.get(3).setText(String.format("%d", mi.totalMem - consoleState.totalMemory)); } else { totalViews.get(0).setVisibility(View.GONE); totalViews.get(1).setVisibility(View.GONE); totalViews.get(2).setVisibility(View.GONE); } } catch (Exception ex) { m_log.e(ex.getMessage()); } }