public bool ConnectCam() { if (IsConnectedCam) { return(true); } WifiManager.StartScan(); var result = WifiManager?.ScanResults?.FirstOrDefault(r => r.Ssid.Contains(CamSsid)); if (result == null) { return(false); } var config = WifiManager.ConfiguredNetworks.FirstOrDefault(c => c.Ssid.Contains(CamSsid)); if (config == null) { return(false); } return(WifiManager.EnableNetwork(config.NetworkId, true)); }
public IEnumerable <string> Scan() { tmr = new Timer(Timeout, null, TIMEOUT_MILLIS, System.Threading.Timeout.Infinite); wifi.StartScan(); receiverARE.WaitOne(); return(wifiNetworks); }
public void OnAvailableWifiButtonClick(object sender, System.EventArgs e) { if (!Utils.HasPermission(ApplicationContext, Utils.ePermission.WifiPermission)) { Toast.MakeText(ApplicationContext, "Application requires permission to Wi-Fi.", ToastLength.Long).Show(); RequestPermissions(Utils.RequiredWifiPermissions, 0); } else { if (!wifiManager.IsWifiEnabled) { Toast.MakeText(ApplicationContext, "Turning WiFi ON...", ToastLength.Long).Show(); wifiManager.SetWifiEnabled(true); } if (!Utils.HasPermission(ApplicationContext, Utils.ePermission.LocationPermission)) { var GetPermissions = Utils.GetPermissions(); } else { if (wifiReceiver == null) { wifiReceiver = new WifiReceiver(wifiManager, wifiList, ApplicationContext, passwordText, connectButton); } textMessage.Visibility = ViewStates.Invisible; Toast.MakeText(ApplicationContext, "Searching for Wi-fi...", ToastLength.Long).Show(); RegisterReceiver(wifiReceiver, new IntentFilter(WifiManager.ScanResultsAvailableAction)); wifiManager.StartScan(); } } }
public void Scan() { while (true) { try { if (!wifiManager.IsWifiEnabled) { wifiManager.SetWifiEnabled(true); } if (wifiManager.WifiState != Android.Net.WifiState.Enabled) { throw new Exception("Please enable wi-fi."); } wifiManager.StartScan(); } catch (Exception e) { // Console.WriteLine(e.Message); } finally { Task.Delay(500).Wait(); } } }
public List <WiFiInfo> Scan() { tmr = new System.Threading.Timer(Timeout, null, TIMEOUT_MILLIS, System.Threading.Timeout.Infinite); wifi.StartScan(); receiverARE.WaitOne(); return(wiFiInfos); }
public List <SsidModel> GetAvailableNetworks() { _context.RegisterReceiver(WifiReceiver, new IntentFilter(WifiManager.ScanResultsAvailableAction)); _wifiManager = _context.GetSystemService(Context.WifiService) as WifiManager; var res = _wifiManager?.StartScan(); return(_wifiItems); }
public override void OnCreate() { base.OnCreate(); Task.Run(() => UpdateMemebers()); mWifiManager = (WifiManager)GetSystemService(Context.WifiService); RegisterReceiver(mWifiScanReceiver, new IntentFilter(WifiManager.ScanResultsAvailableAction)); mWifiManager.StartScan(); Task.Run(() => CheckAsync()); }
public static void Register() { wifi = (WifiManager)Android.App.Application.Context.GetSystemService(Context.WifiService); // Start a scan and register the Broadcast receiver to get the list of Wifi Networks wifiReceiver = new WifiReceiver(); Android.App.Application.Context.RegisterReceiver(wifiReceiver, new IntentFilter(WifiManager.ScanResultsAvailableAction)); wifi.StartScan(); }
public IEnumerable <WifiSignal> Scan() { using var _ = new Timer(Timeout, null, TimeoutMillis, System.Threading.Timeout.Infinite); _wifi.StartScan(); _receiverReset.WaitOne(); return(_wifiNetworks); }
private void PerformScan() { //check if wifi is enabled if (!wiMan.IsWifiEnabled) { var builder = new Android.App.AlertDialog.Builder(this); builder.SetTitle("Change Wifi Adapter State"); builder.SetMessage("Do You want to turn on WIFI adapter?"); builder.SetPositiveButton("Yes", delegate { wiMan.SetWifiEnabled(true); wiMan.StartScan(); }); builder.SetNegativeButton("No", delegate { }); builder.Show(); } else { wiMan.StartScan(); } }
public IEnumerable <string> GetSsids() { if (LastScanRequest.AddSeconds(SCAN_COOLDOWN) < DateTime.Now) { if (WifiManager.IsWifiEnabled == false) { WifiManager.SetWifiEnabled(true); } WifiManager.StartScan(); LastScanRequest = DateTime.Now.AddSeconds(SCAN_COOLDOWN); } return(WifiManager.ScanResults.Select(f => f.Ssid)); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Set our view from the "main" layout resource SetContentView(Resource.Layout.activity_main); if (!(ContextCompat.CheckSelfPermission(this, locationPermission) == (int)Permission.Granted)) { ActivityCompat.RequestPermissions(this, new String[] { locationPermission, locationfinePermission, bluetoothPermission, bluetoothadminPermission, wifiPermission, changewifiPermission }, requestPermissions); } bluetoothAdapter.Enable(); bluetoothAdapter.StartDiscovery(); BluetoothDeviceReceiver bluetoothDeviceReceiver = new BluetoothDeviceReceiver(); RegisterReceiver(bluetoothDeviceReceiver, new IntentFilter(BluetoothDevice.ActionFound)); WifiManager wifiManager = (WifiManager)Android.App.Application.Context.GetSystemService(Android.Content.Context.WifiService); wifiManager.StartScan(); WifiReceiver wifiReceiver = new WifiReceiver(); RegisterReceiver(wifiReceiver, new IntentFilter(WifiManager.ScanResultsAvailableAction)); /*var networks = wifiManager.ConfiguredNetworks; * string wifi = ""; * * for (int i = 0; i < networks.Count; i++) * { * wifi = wifi + networks[i].Ssid + "\r\n"; * DisplayTextWifi(wifi); * }*/ /*string networkSSID = "WIFI-GUEST"; * string networkPass = ""; * * WifiConfiguration wifiConfig = new WifiConfiguration(); * wifiConfig.Ssid = string.Format("\"{0}\"", networkSSID); * wifiConfig.PreSharedKey = string.Format("\"{0}\"", networkPass); * * int netId = wifiManager.AddNetwork(wifiConfig); * wifiManager.Disconnect(); * wifiManager.EnableNetwork(netId, true); * wifiManager.Reconnect();*/ }
protected override void OnCreate(Bundle savedInstanceState) { OnCreateBase(savedInstanceState); CreateNotificationChannel(); _wifiManager = (WifiManager)GetSystemService(WifiService); if (_wifiManager.IsWifiEnabled == false) { _wifiManager.SetWifiEnabled(true); } _receiverWifi = new WifiScanReceiver(_wifiManager); RegisterReceiver(_receiverWifi, new IntentFilter(WifiManager.ScanResultsAvailableAction)); _wifiManager.StartScan(); }
public static void GetWifiNetworks(Context context, Action <List <string> > wifis) { WiFiNetworks = new List <string>(); // Get a handle to the Wifi wifi = (WifiManager)context.GetSystemService(Context.WifiService); // Start a scan and register the Broadcast receiver to get the list of Wifi Networks var wifiReceiver = new WifiReceiver((list) => { wifis(list); }); context.RegisterReceiver(wifiReceiver, new IntentFilter(WifiManager.ScanResultsAvailableAction)); wifi.StartScan(); }
private void FindDev() { try { btn_Find.Enabled = false; progr_bar.Visibility = ViewStates.Visible; wifiManager = (WifiManager)Application.Context.GetSystemService(WifiService); if (!wifiManager.IsWifiEnabled) { wifiManager.SetWifiEnabled(true); } wifiManager.StartScan(); for (int i = 0; i < wifiManager.ScanResults.Count; i++) { if (wifiManager.ScanResults[i].Ssid.ToString().Contains("SH_")) { Button exist = (Button)m_frame_control.FindViewWithTag(wifiManager.ScanResults[i].Ssid.ToString()); if (exist == null) { LinearLayout.LayoutParams leftMarginParams = new LinearLayout.LayoutParams(-1, -2); Button btn1 = new Button(this); btn1.Text = wifiManager.ScanResults[i].Ssid.ToString(); btn1.Tag = wifiManager.ScanResults[i].Ssid.ToString(); btn1.SetBackgroundResource(Resource.Drawable.btn_AddDev_selector); btn1.SetTextColor(new Android.Graphics.Color(0xED, 0xED, 0xED)); btn1.Tag = wifiManager.ScanResults[i].Ssid.ToString(); btn1.Click += Btn1_Click; m_frame_control.AddView(btn1, leftMarginParams); } } } progr_bar.Visibility = ViewStates.Invisible; btn_Find.Enabled = true; } catch (Exception ex) { Toast.MakeText(this, ex.Message, ToastLength.Short); } }
public List <string> AvailableWifiAPs() { bool scanStatus = _manager.StartScan(); if (scanStatus) { IList <ScanResult> scanResults = _manager.ScanResults; List <string> networkNames = new List <string>(); foreach (ScanResult scanResult in scanResults) { networkNames.Add(scanResult.Ssid); } return(networkNames); } else { return(null); } }
public void getNetworks() { _done = false; var context = Android.App.Application.Context; if (context == null) { return; } wifi = (WifiManager)context.GetSystemService(Context.WifiService); if (!wifi.IsWifiEnabled) { wifi.SetWifiEnabled(true); } wifiReceiver = new WifiReceiver(); context.RegisterReceiver(wifiReceiver, new IntentFilter(WifiManager.ScanResultsAvailableAction)); wifi.StartScan(); }
public override void OnReceive(Context context, Intent intent) { _sessionManagerWorkStorage = new WorkSessionManager(context); var wifiFound = false; if (!intent.Action.Equals(WifiManager.ScanResultsAvailableAction)) { return; } WifiNetworks = WifiManager.ScanResults.ToDomainWifiNetworks().ToList(); foreach (var availableSsid in _availableSsids) { var wifi = WifiNetworks.FirstOrDefault(n => n.Ssid == availableSsid); if (wifi == null) { _wifiLost = true; continue; } _wifiLost = false; if (_sessionManagerWorkStorage.GetIsAtWork()) { continue; } wifiFound = true; FoundNetworkNotify(context, wifi); } if (!wifiFound & _wifiLost) { if (_sessionManagerWorkStorage.GetIsAtWork()) { LostNetworkNotify(context); } } Task.Run(() => { Thread.Sleep((long)TimeSpan.FromSeconds(5).TotalMilliseconds); WifiManager.StartScan(); }); }
public void GetWifiNetworks() { searching = true; wifi = (WifiManager)context.GetSystemService(Context.WifiService); context.RegisterReceiver(this, new IntentFilter(WifiManager.ScanResultsAvailableAction)); try { // If cannot start scan trow a error if (wifi.StartScan() == false) { ErrorLoading(this, new EventArgs()); return; } } catch (Exception e) { Debug.WriteLine(e.Message); } }
public async void Refresh() { if (IsRefreshing) { return; } await Task.Run(() => { IsRefreshing = true; // There's no other form right now to scan for new wifi access points _manager.StartScan(); Thread.Sleep(7000); IsRefreshing = false; }); RefreshDone?.Invoke(this, EventArgs.Empty); }
public async Task GetNetworksAsync(bool repeat, int intervalMs, Action <ServiceResult> complete) { _StopMonitor = false; // no point in wasting CPU cycles if no-one is listening if (complete == null) { return; } while (true) { try { // see if we can enumerate all nearby wifis var success = _WifiManager.StartScan(); if (!success) { complete(new ServiceResult { Status = ServiceResultStatus.Failure, Message = "Check that Wifi is enabled." }); } complete(new ServiceResult <List <NetworkSignal> > { Status = ServiceResultStatus.Success, Payload = _WifiManager.ScanResults.Select(r => new NetworkSignal { MacAddress = r.Bssid, Ssid = r.Ssid, Level = r.Level }).ToList() }); if (!repeat || _StopMonitor) { return; } await Task.Delay(intervalMs); } catch (Exception ex) { complete(new ServiceResult <Exception> { Status = ServiceResultStatus.Error, Payload = ex }); } } }
private void GetWifiNetworks() { wiFiNetworks = new List <WiFiNetwork>(); // Get a handle to the Wifi wifi = (WifiManager)context.GetSystemService(Context.WifiService); // check wifi is not disabled if (wifi.WifiState != WifiState.Enabled) { Android.Widget.Toast.MakeText(this, "WiFi disabled, enabling wifi network...", Android.Widget.ToastLength.Short).Show(); wifi.SetWifiEnabled(true); Task.Delay(3000); } // Start a scan and register the Broadcast receiver to get the list of Wifi Networks var wifiReceiver = new WifiReceiver(); var wifiSignal = new WiFiSignalChanged(); context.RegisterReceiver(wifiReceiver, new IntentFilter(WifiManager.ScanResultsAvailableAction)); // list of networks changed //context.RegisterReceiver(wifiSignal, new IntentFilter(WifiManager.RssiChangedAction)); // signal strength changed wifi.StartScan(); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); this.SetContentView(Resource.Layout.StepOne); TextView txtInternetCheck = FindViewById <TextView>(Resource.Id.txtInternetCheck); TextView wifiName = FindViewById <TextView>(Resource.Id.wifiName); EditText wifiPass = FindViewById <EditText>(Resource.Id.wifiPass); ListView wifiNetworkList = FindViewById <ListView>(Resource.Id.listView1); Button connBtn = FindViewById <Button>(Resource.Id.wifiConnBtn); Button stepTwoBtn = FindViewById <Button>(Resource.Id.stepTwoBtn); WifiManager wifiManager = (WifiManager)Application.Context.GetSystemService(WifiService); ArrayList networks = new ArrayList(); if (wifiManager.StartScan()) { foreach (ScanResult network in wifiManager.ScanResults) { networks.Add(network.Ssid); } } //connBtn.Visibility = Android.Views.ViewStates.Invisible; stepTwoBtn.Visibility = Android.Views.ViewStates.Invisible; //Turn on wifi if not enabled if (!wifiManager.IsWifiEnabled) { wifiManager.SetWifiEnabled(true); } //Supplies wifi connections picked up var adapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleListItem1, networks); wifiNetworkList.Adapter = adapter; //When network name gets clicked wifiNetworkList.ItemClick += WifiItemClicked; //Gets SSID of item clicked void WifiItemClicked(object sender, AdapterView.ItemClickEventArgs e) { string selectedItem = (string)networks[e.Position]; wifiName.Visibility = Android.Views.ViewStates.Visible; wifiPass.Visibility = Android.Views.ViewStates.Visible; connBtn.Visibility = Android.Views.ViewStates.Visible; wifiName.Text = selectedItem; wifiPass.Hint = $"Enter password for {selectedItem}"; } //Connect to the wifi connBtn.Click += delegate { InputMethodManager inputManager = (InputMethodManager)this.GetSystemService(Context.InputMethodService); inputManager.HideSoftInputFromWindow(this.CurrentFocus.WindowToken, HideSoftInputFlags.NotAlways); var wifiConfig = new WifiConfiguration(); wifiConfig.Ssid = string.Format("\"{0}\"", wifiName.Text); wifiConfig.PreSharedKey = string.Format("\"{0}\"", wifiPass.Text); using (WifiManager wifiManager2 = (WifiManager)Application.Context.GetSystemService(Context.WifiService)) { int netId = wifiManager2.AddNetwork(wifiConfig); wifiManager2.Disconnect(); wifiManager2.EnableNetwork(netId, true); wifiManager2.Reconnect(); } txtInternetCheck.Text = "Connecting...Please Wait"; //Thread.Sleep(7000); //ConnectivityManager connectivityManager = (ConnectivityManager)Application.Context.GetSystemService(Context.ConnectivityService); //var netInfo = connectivityManager.ActiveNetworkInfo; ////netInfo.IsConnected && //if (netInfo.Type == ConnectivityType.Wifi) //{ // txtInternetCheck.Text = "Great, you are connected!"; // stepTwoBtn.Visibility = Android.Views.ViewStates.Visible; //} //else //{ // txtInternetCheck.Text = "Something went wrong. Please try again."; //} Thread thread = new Thread(() => { Thread.Sleep(7000); ConnectivityManager connectivityManager = (ConnectivityManager)Application.Context.GetSystemService(Context.ConnectivityService); var netInfo = connectivityManager.ActiveNetworkInfo; //netInfo.IsConnected && if (netInfo.Type == ConnectivityType.Wifi) { RunOnUiThread(() => { txtInternetCheck.Text = "Great, you are connected!"; stepTwoBtn.Visibility = Android.Views.ViewStates.Visible; }); } else if (netInfo == null) { RunOnUiThread(() => { txtInternetCheck.Text = "Something went wrong. Please try again."; }); } }); thread.Start(); }; stepTwoBtn.Click += delegate { Intent intent = new Intent(this, typeof(ActivateActivity)); StartActivity(intent); Finish(); }; }
/// <summary> /// поиск точек Wi-Fi /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button_Click(object sender, EventArgs e) { RegisterReceiver(m_scanResultBroadcastReceiver, new IntentFilter(WifiManager.ScanResultsAvailableAction)); button.Text = "Непрерывный поиск..."; WifiManager.StartScan(); }
private void GetWifiNetworks() { if (!IsScanning) { if (RefreshTime < 10) { Toast.MakeText(Android.App.Application.Context, "You have to set refresh time first!", ToastLength.Short).Show(); } else { IsScanning = true; Toast.MakeText(Android.App.Application.Context, "Scanning has been started!", ToastLength.Short).Show(); var locator = CrossGeolocator.Current; locator.DesiredAccuracy = 5; var startTimeSpan = TimeSpan.Zero; var periodTimeSpan = TimeSpan.FromSeconds(RefreshTime); timer = new Timer(async(e) => { ListOfWifiNetworks.Clear(); wifiManager = (WifiManager)context.GetSystemService(Context.WifiService); await locator.StartListeningAsync(TimeSpan.FromSeconds(1), 0.01, false, null); var position = await locator.GetPositionAsync(TimeSpan.FromSeconds(20), null, true); if (wifiManager.ConnectionInfo.NetworkId != -1 && wifiManager.ConnectionInfo.SSID != "UNKNOWNSSID") { CurrentWifiNetworkName = wifiManager.ConnectionInfo.SSID; CurrentWifiNetworkIP = wifiManager.ConnectionInfo.IpAddress; CurrentWifiNetworkIPText = Android.Text.Format.Formatter.FormatIpAddress(CurrentWifiNetworkIP); CurrentWifiNetworkSpeed = wifiManager.ConnectionInfo.LinkSpeed; } else { CurrentWifiNetworkName = "-"; CurrentWifiNetworkIPText = "-"; CurrentWifiNetworkSpeed = 0; } Latitude = position.Latitude; Longitude = position.Longitude; wifiReceiver = new WifiReceiver(); context.RegisterReceiver(wifiReceiver, new IntentFilter(WifiManager.ScanResultsAvailableAction)); IsBusy = true; wifiManager.StartScan(); CollectionofNetworksArrived.WaitOne(); context.UnregisterReceiver(wifiReceiver); if (ListOfWifiNetworks.Count > 0) { DetectedWifiNetworks.Clear(); foreach (var item in ListOfWifiNetworks) { DetectedWifiNetworks.Add(item); } } CollectionofNetworksArrived.Reset(); IsBusy = false; if (AutoSaveToDatabase) { Device.BeginInvokeOnMainThread(async() => { await SaveListToDatabase(); }); } if (AutoSaveToFile) { Device.BeginInvokeOnMainThread(() => { SaveListToFile(); }); } NumberOfDetectedAccessPoints = DetectedWifiNetworks.Count; await locator.StopListeningAsync(); }, null, startTimeSpan, periodTimeSpan); } } else { Toast.MakeText(Android.App.Application.Context, "Scanning has already started!", ToastLength.Short).Show(); } }
private async void updateView() { // while (true) { //int k = 0; //int j = 0; lblOutput.Text = string.Empty; _wifi.ScanResults.Clear(); //Application.Context.RegisterReceiver(_wifiReceiver, new IntentFilter(WifiManager.ScanResultsAvailableAction)); _wifi.StartScan(); FOUND = new List <ScanResult>(); TEMP = new List <ScanResult>(); try { for (int j = 0; j < _wifi.ScanResults.Count; j++) { setdist(_wifi.ScanResults[j].Bssid, _wifi.ScanResults[j].Ssid, _wifi.ScanResults[j].Level, _wifi.ScanResults[j].Frequency); } for (int x = 0; x < _wifi.ScanResults.Count; x++) { TEMP.Add(_wifi.ScanResults[x]); } } catch (Exception e) { MetroLog.InternalLogger.Current.Error("Error occurred at display", e); Console.WriteLine("Double for : " + e); } int bestindex = 0; double bestmeter = 9999.9; try { for (int k = 0; 0 < TEMP.Count; k++) { bestmeter = 9999.9; for (int j = 0; j < TEMP.Count; j++) { if (getdist(TEMP[j].Bssid, TEMP[j].Ssid) < bestmeter) { bestmeter = getdist(TEMP[j].Bssid, TEMP[j].Ssid); bestindex = j; } } FOUND.Add(TEMP[bestindex]); TEMP.RemoveAt(bestindex); } } catch (Exception e) { MetroLog.InternalLogger.Current.Error("Error occurred at display", e); Console.WriteLine("Sorting : " + e); } //Display Results try { for (int k = 0; k < FOUND.Count; k++) { lblOutput.Text = lblOutput.Text + "SSID: " + FOUND[k].Ssid + "\nMAC: " + FOUND[k].Bssid + " RSSI: " + FOUND[k].Level + "dBm Frequency: " + FOUND[k].Frequency + "MHz\nDistance from access point: " + String.Format(" {0:F2}", getdist(FOUND[k].Bssid, FOUND[k].Ssid)) + "m" + "\n\n"; } } catch (Exception e) { Console.WriteLine("Display : " + e); MetroLog.InternalLogger.Current.Error("Error occurred at display", e); } await Task.Delay(4000); } }
public async Task CheckAsync() { while (!Destroyed) { try { if (mWifiManager == null) { mWifiManager = (WifiManager)GetSystemService(Context.WifiService); RegisterReceiver(mWifiScanReceiver, new IntentFilter(WifiManager.ScanResultsAvailableAction)); mWifiManager.StartScan(); await Task.Delay(10000); } if (mWifiManager.ScanResults == null) { mWifiManager.StartScan(); await Task.Delay(10000); } if (mWifiManager.ScanResults.Count != 0) { if (mWifiManager.ScanResults.ToList().Any(x => x.Ssid.ToLower().Contains("insidev"))) { Task.Run(() => Notification("Esi Startup", "Sveikas atvykęs į Pertraukties tašką")); while (MemebersModelsList == null) { await Task.Delay(1000); } if (!MemebersModelsList.First(x => x.Name.Contains(CurrentMemberName)).Active) { CreateNotificationChannel(); await Task.Run(() => Start()); await Task.Run(() => UpdateMemebers()); } } else { Task.Run(() => Notification("Nesi Startup", "")); while (MemebersModelsList == null) { await Task.Delay(1000); } if (MemebersModelsList.First(x => x.Name.Contains(CurrentMemberName)).Active) { await Task.Run(() => Stop()); await Task.Run(() => UpdateMemebers()); } } } await Task.Delay(10000); } catch (Exception e) { Task.Run(() => Notification("Error", e.Message)); } } }