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:de.ribeiro.android.gso.core.MyContext.java
/** * @param context/*from www . jav a2 s . c o m*/ * @return * @author Tobias Janssen * <p/> * Prft, ob eine Wlan verbindung besteht, und liefert das Ergebnis */ public Boolean isWifiConnected() { WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiinfo = wifi.getConnectionInfo(); return wifiinfo.getNetworkId() != -1; }
From source file:com.google.example.gcmnetworkmanagerquickstart.MainActivity.java
@Override public void onClick(View v) { switch (v.getId()) { case R.id.button_start_wifi_task: startWifiTask();/*from w w w. j a v a2 s .co m*/ break; case R.id.button_start_charging_task: startChargingTask(); break; case R.id.button_turn_on_wifi: WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); wifi.setWifiEnabled(true); break; case R.id.button_start_periodic_task: startPeriodicTask(); break; case R.id.button_stop_periodic_task: stopPeriodicTask(); break; } }
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 w w w . j a v 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:org.csploit.android.WifiScannerActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); SharedPreferences themePrefs = getSharedPreferences("THEME", 0); Boolean isDark = themePrefs.getBoolean("isDark", false); if (isDark)/*w w w . j a va 2s . c om*/ setTheme(R.style.DarkTheme); else setTheme(R.style.AppTheme); setContentView(R.layout.wifi_scanner); mWifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE); mClipboard = (ClipboardManager) this.getSystemService(Context.CLIPBOARD_SERVICE); mWifiMatcher = new WirelessMatcher(getResources().openRawResource(R.raw.alice)); mScanReceiver = new ScanReceiver(); mConnectionReceiver = new ConnectionReceiver(); mStatusText = (TextView) findViewById(R.id.scanStatusText); mAdapter = new ScanAdapter(); mKeyList = new ArrayList<>(); getListView().setAdapter(mAdapter); mStatusText.setText(getString(R.string.wifi_initializing)); if (!mWifiManager.isWifiEnabled()) { mStatusText.setText(getString(R.string.wifi_activating_iface)); mWifiManager.setWifiEnabled(true); mStatusText.setText(getString(R.string.wifi_activated)); } mScanReceiver.register(this); if (mMenu != null) { MenuItem menuScan = mMenu.findItem(R.id.scan); MenuItemCompat.setActionView(menuScan, new ProgressBar(this)); } mStatusText.setText(getString(R.string.wifi_scanning)); mScanning = true; mWifiManager.startScan(); }
From source file:com.codestation.henkakuserver.MainActivity.java
public boolean isConnectedInWifi(boolean wifiOnly) { WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); NetworkInfo networkInfo = ((ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE)) .getActiveNetworkInfo();/*from w ww. j a v a2 s . com*/ boolean wifiEnabled = networkInfo != null && networkInfo.isAvailable() && networkInfo.isConnected() && wifiManager.isWifiEnabled() && networkInfo.getTypeName().equals("WIFI"); if (!wifiOnly && !wifiEnabled) { try { final Method method = wifiManager.getClass().getDeclaredMethod("isWifiApEnabled"); method.setAccessible(true); wifiEnabled = (Boolean) method.invoke(wifiManager); } catch (Exception e) { e.printStackTrace(); } } return wifiEnabled; }
From source file:totalcross.android.ConnectionManager4A.java
public static String getLocalHost() { try {/*from w w w.ja v a 2 s . c o m*/ ConnectivityManager connMgr = (ConnectivityManager) Launcher4A.loader .getSystemService(Context.CONNECTIVITY_SERVICE); int type = connMgr.getActiveNetworkInfo().getType(); if (type == ConnectivityManager.TYPE_WIFI) { WifiManager wifiMgr = (WifiManager) Launcher4A.loader.getSystemService(Context.WIFI_SERVICE); return ipAddressToString(wifiMgr.getDhcpInfo().ipAddress); } String ip = getLocalIpAddress(); return ip != null ? ip : InetAddress.getLocalHost().getHostAddress(); } catch (Exception e) { } return "127.0.0.1"; }
From source file:com.lge.helloFriendsCamera.ConnectionActivity.java
private void initialize() { mContext = this; // initialize connectionManager mConnectionManager = OctopusManager.getInstance(mContext).getConnectionManager(); mWifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); updateScanStateUI();// w ww . j a v a2 s . co m }
From source file:de.teambluebaer.patientix.activities.LoginActivity.java
/** * Method to get the MACAddress of the device * * @return String of the MACAddress of the device *///from w w w. ja va 2 s .c o m private String getMacAddress() { WifiManager manager = (WifiManager) getSystemService(Context.WIFI_SERVICE); WifiInfo info = manager.getConnectionInfo(); return info.getMacAddress(); }
From source file:org.basdroid.common.NetworkUtils.java
/** * check if enable wifi device// w w w . j a v a2 s. c o m * @param context * @return */ public static boolean isWifiEnabled(Context context) { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); return wifiManager.isWifiEnabled(); }
From source file:es.glasspixel.wlanaudit.fragments.ScanFragment.java
public void initScan() { // WifiManager initialization if (mWifiManager == null) mWifiManager = (WifiManager) getActivity().getSystemService(Context.WIFI_SERVICE); if (mWifiManager != null) { // If WiFi is disabled, enable it if (!mWifiManager.isWifiEnabled() && prefs.getBoolean("wifi_autostart", true)) { mWifiManager.setWifiEnabled(true); mWasWifiTurnedOn = true;// w w w . j av a 2s. c om } else { mWasWifiTurnedOn = false; } new RefreshAction(getActivity()); setupNetworkScanCallBack(); if (!mIsScanning) this.startScan(); } else { mCallback.scanCompleted(); empty_text.setText(getSherlockActivity().getResources().getString(R.string.no_networks_found)); list_view.setEmptyView(getSherlockActivity().findViewById(R.id.empty)); } }