List of usage examples for android.net.wifi WifiManager isWifiEnabled
public boolean isWifiEnabled()
From source file:net.helff.wificonnector.WifiConnectorActivity.java
protected void startScan() { WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE); if (wifiManager != null && wifiManager.isWifiEnabled()) { wifiManager.startScan();//from www .j av a 2s . c o m } }
From source file:net.olejon.spotcommander.AddComputerActivity.java
private void scanNetwork() { if (mNetworkScanTask != null && mNetworkScanTask.getStatus() == AsyncTask.Status.RUNNING) { mNetworkScanTask.cancel(true);/*from www.j a va 2s .c om*/ } else { final WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE); if (wifiManager.isWifiEnabled()) { final WifiInfo wifiInfo = wifiManager.getConnectionInfo(); final int wifiIpAddress = wifiInfo.getIpAddress(); final String wifiSubnet = String.format("%d.%d.%d", (wifiIpAddress & 0xff), (wifiIpAddress >> 8 & 0xff), (wifiIpAddress >> 16 & 0xff)); if (wifiSubnet.equals("0.0.0")) { mTools.showToast(getString(R.string.add_computer_wifi_not_connected), 0); } else { mNetworkScanTask = new NetworkScanTask(); mNetworkScanTask.execute(wifiSubnet); } } else { mTools.showToast(getString(R.string.add_computer_wifi_not_connected), 0); } } }
From source file:com.laer.easycast.VideoPane.java
public void videoRaw(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 VideoAirplay().execute(); } else if (obj.URL == null || wifi.isWifiEnabled() != true) { WiFiOptions();/*from w w w. ja v a 2 s . c o m*/ if (obj.URL == null) { Toast.makeText(getActivity(), "No compatible devices found", Toast.LENGTH_SHORT).show(); } } }
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.codestation.henkakuserver.MainActivity.java
public boolean isConnectedInWifi(boolean wifiOnly) { WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); NetworkInfo networkInfo = ((ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE)) .getActiveNetworkInfo();// w ww. j a v a 2 s . c om 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:com.cubic9.android.droidglove.Main.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // prevent sleep PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "DroidGlove"); // vibrator// w w w . j a va 2 s . c o m mVibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE); // sensor mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); // show error dialog if Wi-Fi off and Tethering off. WifiManager wifi = (WifiManager) getSystemService(WIFI_SERVICE); if ((!wifi.isWifiEnabled()) && (!isTethering(wifi))) { new AlertDialog.Builder(Main.this).setIcon(android.R.drawable.ic_dialog_alert) .setTitle(getString(R.string.dialog_error_title)) .setMessage(getString(R.string.dialog_error_wifi_off)) .setPositiveButton(R.string.dialog_error_ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { appEnd(); } }).create().show(); } // get IP address getPreferences(); // check IP address if (ip.equals("")) { showToast(R.string.toast_error_ip_null); Intent intent = new Intent(this, Settings.class); startActivityForResult(intent, 0); } else if (!ip.matches("^([0-9]{1,3}\\.){3}[0-9]{1,3}$")) { showToast(R.string.toast_error_ip_wrong); Intent intent = new Intent(this, Settings.class); startActivityForResult(intent, 0); } // init angle for (int i = 0; i < 3; i++) { for (int j = 0; j < AVERAGE_AMOUNT; j++) { mOrigAngles[i][j] = 0; } } // show screen setContentView(R.layout.main); // find views mTextViewMessage = (TextView) findViewById(R.id.textViewMessage); mTextViewIp = (TextView) findViewById(R.id.textViewIp); /* * textViewX = (TextView) findViewById(R.id.textViewX); textViewY = * (TextView) findViewById(R.id.textViewY); textViewZ = (TextView) * findViewById(R.id.textViewZ); textViewGrip = (TextView) * findViewById(R.id.textViewGrip); */ Button button = (Button) findViewById(R.id.buttonReset); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mInitirizedSensor = false; mTextViewMessage.setText(R.string.message_swipe_down); } }); }
From source file:com.yoval.community.chatapp.DistanceActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_distance); displayLocationSettingsRequest(getApplicationContext()); if (googleServicesAvalaible()) { //Toast.makeText(this, "Perfect", Toast.LENGTH_LONG).show(); initMap();//ww w . j av a 2 s . c om } else { Toast.makeText(this, "Play services problem", Toast.LENGTH_LONG).show(); } //Check for WIfi services enabled WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); if (!wifi.isWifiEnabled()) { showWifiRequest(); } CustomizedLocationListener locationListener = new CustomizedLocationListener(getApplicationContext()); locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); if (ContextCompat.checkSelfPermission(this, Manifest.permission.MAPS_RECEIVE) != PackageManager.PERMISSION_GRANTED) { locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 5 * 60 * 1000, 10, locationListener); } if (FirebaseAuth.getInstance().getCurrentUser() == null) { // Start sign in/sign up activity startActivityForResult(AuthUI.getInstance().createSignInIntentBuilder().build(), SIGN_IN_REQUEST_CODE); } else { // User is already signed in. Therefore, display // a welcome Toast Toast.makeText(this, R.string.Bienvenue + " " + FirebaseAuth.getInstance().getCurrentUser().getDisplayName(), Toast.LENGTH_LONG).show(); } Toolbar toolbar = (Toolbar) findViewById(R.id.toolbarDistance); setSupportActionBar(toolbar); SeekBar distanceBar = (SeekBar) findViewById(R.id.seekBarDistance); // make seekbar object distanceBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } @Override public void onStartTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { // TODO Auto-generated method stub TextView textViewDistance = (TextView) findViewById(R.id.textViewDistance); textViewDistance.setText(progress + " Km"); radius = progress; SaveUserInformations(radius); updateZoomMap(); } }); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.distNext); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { goToDetailView(); } }); // ATTENTION: This was auto-generated to implement the App Indexing API. // See https://g.co/AppIndexing/AndroidStudio for more information. client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); }
From source file:riddimon.android.asianetautologin.CredentialActivity.java
private void refreshNetworkSpinnerIfNecessary() { if (mSsids != null && mSsids.size() != 0) return;//from w ww .j a v a 2 s .c om //get wifi networks WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE); List<WifiConfiguration> lwc = wm.getConfiguredNetworks(); WifiInfo wi = wm.getConnectionInfo(); String wssid = null; if (wi != null && wm.isWifiEnabled()) { String ssid = wi.getSSID(); if (!TextUtils.isEmpty(ssid)) { wssid = ssid.replace("\"", ""); } } mSsids = new ArrayList<String>(); int selection = 0; if (lwc != null) { int i = -1; for (WifiConfiguration wc : lwc) { i++; String ssid = TextUtils.isEmpty(wc.SSID) ? "" : wc.SSID.replace("\"", ""); mSsids.add(ssid); if (!TextUtils.isEmpty(wssid) && ssid.equals(wssid)) { selection = i; } } } mSsid.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, mSsids)); if (mSsids != null && mSsids.size() > 0) { mSsid.setSelection(selection); } }
From source file:at.ac.uniklu.mobile.sportal.service.MutingService.java
private void mute(int alarmId) { Log.d(TAG, "mute()"); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); if (Preferences.getLocationStatus(preferences) == Preferences.LOCATION_STATUS_WAITING) { Log.d(TAG, "mute() blocked - waiting for a location update"); return;//from www . j a va 2 s.c o m } // check if phone is already muted by the user AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE); boolean isPhoneAlreadyMuted = audioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL && !Preferences.isMutingPeriod(preferences); if (isPhoneAlreadyMuted) { Log.d(TAG, "phone is already muted, scheduling next mute"); scheduleMute(true); return; } // load the current period from the db MutingPeriod mutingPeriod = null; Log.d(TAG, "muting period id: " + alarmId); if (DEBUG_WITH_FAKE_ALARMS) { mutingPeriod = new MutingPeriod(); mutingPeriod.setId(-1); mutingPeriod.setBegin(System.currentTimeMillis()); mutingPeriod.setEnd(mutingPeriod.getBegin() + 10000); mutingPeriod.setName("Fakeevent"); } else { mutingPeriod = Studentportal.getStudentPortalDB().mutingPeriods_getPeriod(alarmId); } // check if phone is located at university notifyUser(Studentportal.NOTIFICATION_MS_INFO, true, mutingPeriod.getName(), mutingPeriod.getName(), getString(R.string.automute_notification_course_started_locating)); boolean isPhoneLocationKnown = false; boolean isPhoneLocatedAtUniversity = false; String locationSource = null; WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE); if (wifiManager.isWifiEnabled()) { ScanResult scanResult = MutingUtils.findMutingWifiNetwork(wifiManager.getScanResults()); if (scanResult != null) { Log.d(TAG, "phone located by wifi: " + scanResult.SSID); isPhoneLocationKnown = true; isPhoneLocatedAtUniversity = true; locationSource = "wifi (" + scanResult.SSID + ")"; } } if (!isPhoneLocationKnown) { // phone location could not be determined by wifi, trying network location instead... LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { Intent locationIntent = new Intent("at.ac.uniklu.mobile.sportal.LOCATION_UPDATE") .putExtra(EXTRA_ALARM_ID, alarmId); PendingIntent pendingLocationIntent = PendingIntent.getBroadcast(this, 0, locationIntent, PendingIntent.FLAG_UPDATE_CURRENT); // remove the location receiver (so it doesn't get registered multiple times [could also happen on overlapping mute() calls) locationManager.removeUpdates(pendingLocationIntent); if (Preferences.getLocationStatus(preferences) == Preferences.LOCATION_STATUS_RECEIVED) { isPhoneLocationKnown = true; pendingLocationIntent.cancel(); Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if (location == null) { Log.d(TAG, "location received but still null"); } else { MutingRegion mutingRegion = MutingUtils.findOverlappingMutingRegion(location); if (mutingRegion != null) { Log.d(TAG, "phone located by network @ " + mutingRegion.getName()); isPhoneLocatedAtUniversity = true; locationSource = "location (" + mutingRegion.getName() + ")"; } } } else { Log.d(TAG, "trying to locate the phone by network..."); // wait for a location update Preferences.setLocationStatus(preferences, Preferences.LOCATION_STATUS_WAITING); locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, pendingLocationIntent); return; // exit method - it will be re-called from the location broadcast receiver on a location update } } } boolean isAlwaysMuteEnabled = Preferences.isAutomuteWithoutLocation(this, preferences); if (isPhoneLocationKnown) { if (!isPhoneLocatedAtUniversity) { Log.d(TAG, "phone is not located at university, scheduling next mute"); scheduleMute(true); removeNotification(Studentportal.NOTIFICATION_MS_INFO); return; } } else { Log.d(TAG, "phone cannot be located"); if (!isAlwaysMuteEnabled) { Log.d(TAG, "alwaysmute is disabled, scheduling next mute"); Preferences.setLocationStatus(preferences, Preferences.LOCATION_STATUS_NONE); scheduleMute(true); removeNotification(Studentportal.NOTIFICATION_MS_INFO); return; } } // only turn the ringtone off if we aren't currently in a muting period. // if we are in a muting period the ringtone is already muted and the request should be ignored, // else rintoneTurnOn() won't turn the ringtone back on because ringtone override will be set to true if (!Preferences.isMutingPeriod(preferences)) { MutingUtils.ringtoneTurnOff(this); } // persist that from now on the phone is in a muting period Preferences.setMutingPeriod(preferences, true); // inform user via a notification that a course has started and the phone has been muted notifyUser(Studentportal.NOTIFICATION_MS_INFO, true, mutingPeriod.getName(), mutingPeriod.getName(), getString(R.string.automute_notification_course_muted)); final boolean isPhoneLocationKnownAnalytics = isPhoneLocationKnown; final String locationSourceAnalytics = locationSource; Analytics.onEvent(Analytics.EVENT_MUTINGSERVICE_MUTE, "isPhoneLocationKnown", isPhoneLocationKnownAnalytics + "", "locationSource", locationSourceAnalytics); scheduleUnmute(mutingPeriod.getEnd()); }